8

Unlike isearch, evil-search mode ignores case-fold-search option.

Using evil-search like this for eg:

(setq-default evil-search-module 'evil-search)

Is it possible to make evil-search case sensitive?

3
  • Looking at evil-search source, it looks like it follows search-upper-case instead Commented Mar 10, 2017 at 12:40
  • FTR, for making the / search case-sensitive, case-fold-search is the right option. Commented Jan 27, 2020 at 15:16
  • IIRC smart search overrides case-fold-search in this spesific case.
    – ideasman42
    Commented Jan 28, 2020 at 5:12

2 Answers 2

11

What to do

You can customize the variable evil-ex-search-case to tell it what you want evil to do when searching. Here's the docstring:

evil-ex-search-case is a variable defined in evil-vars.el. Its value is smart

Documentation:

The case behaviour of the search command. Smart case means that the pattern is case sensitive if and only if it contains an upper case letter, otherwise it is case insensitive.

You can customize this variable.

If you dig into the source code, this is the variable in question:

(defcustom evil-ex-search-case 'smart
  "The case behaviour of the search command.
Smart case means that the pattern is case sensitive if and only
if it contains an upper case letter, otherwise it is case
insensitive."
  :type '(radio (const :tag "Case sensitive." sensitive)
                (const :tag "Case insensitive." insensitive)
                (const :tag "Smart case." smart))
  :group 'evil)

Now: you can either use the customize interface to choose your option, or you could put the following in your init file:

(setq evil-ex-search-case 'sensitive)

Here's how I found this information.

First, I asked apropos to tell me about various functions and variables related to evil searches (M-x apropos evil search). I then searched that list for mentions of "case," and checked out the variable evil-ex-search-case. When that looked like the relevant variable, I followed the link in the help window to the source code to figure out what value I needed to set it to.

2
  • Thanks for the comprehensive answer, I'd actually read over the source code for evil-search but found multiple terms that mention case (evil-ex-regex-case. evil-ex-regex-without-case, evil-ex-pattern-ignore-case)... so wasn't sure which was important to access.
    – ideasman42
    Commented Mar 11, 2017 at 6:25
  • This worked for me only after also going into emacs menu Options->Default Search Options, and unchecking "ignore case" Commented Sep 26, 2020 at 1:28
2

Super old question, but for anyone looking for a more vim-like solution, try this:

(defun set-noic() 
  "set case sensitive" 
  (interactive) 
  (setq evil-ex-search-case 'sensitive))
(defun set-ic() 
  "set ignore case" 
  (interactive) 
  (setq evil-ex-search-case 'insensitive))

Then you can change case sensitivity using :set-ic or :set-noic, just like you did in vim. Just have to remember the dash.

1
  • You just taught me that interactive functions could be called via the ex command line. I had no idea I could skip hitting M-x and just use : instead. Thank you.
    – g-gundam
    Commented Oct 1, 2022 at 1:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.