Next: Working with unprintable characters, Previous: Replacing highlighted text, Up: Common requests [Contents][Index]

### 5.11 How do I control Emacs’s case-sensitivity when searching/replacing?

The value of the variable `case-fold-search` determines whether searches are case sensitive:

    (setq case-fold-search nil) ; make searches case sensitive
    (setq case-fold-search t)   ; make searches case insensitive

Similarly, for replacing, the variable `case-replace` determines whether replacements preserve case.

You can also toggle case sensitivity at will in isearch with `M-c`.

To change the case sensitivity just for one major mode, use the major mode’s hook. For example:

    (add-hook 'foo-mode-hook
              (lambda ()
               (setq case-fold-search nil)))