Search code examples
replaceemacscase-sensitive

emacs: how do I do a case-sensitive replace string


I am trying to replace all \gamma with \zeta in a region. I do not want to touch the \Gamma. I am quite decided on doing this, and I do not really want to go through a query-replace. I do M-x replace string: <RET> \gamma <RET> \zeta <RET> but this replaces both \gamma and \Gamma with \zeta. How do I get only the \gamma to be replaced with \zeta, leaving the \Gamma untouched?


Solution

  • You can set case-fold-search to nil before calling query-replace:

    Type M - : (meta-colon), then (setq case-fold-search nil), then continue normally. The setting will apply only to your current buffer. Revert back to the default behavior by setting case-fold-search to t again.