4

I'm trying to perform a search and replace in spacemacs but I need it to be case sensitive when by default it appears to be case insensitive. So I try to do :set noignorecase but then I have this error message :

State noignore case cannot be set as initial evil state

Any idea how to perform a case sensitive search and replace with spacemacs?

3

Short and narrow answer

You need to set the variable case-fold-search to nil in order to have case sensitive search. So: put this somewhere in your init file:

(setq case-fold-search nil)

See the manual node on Searching and Case for more details.

Some background explanation

spacemacs relies heavily on evil, which emulates Vim. In general, you should not expect it to accept all (or even most) of Vim's syntax. :set noignorecase is straight out of Vim, but there is no set command in evil's limited set of ex commands.

The reason you got the error messages you did is (I think) because evil tries to match partially completed commands. In browsing through the list of ex commands evil emulates (hit C-h v evil-ex-commands to see the list), the only command that starts with set is:

("set-initial-state" . evil-ex-set-initial-state)

So, in effect, you tried to tell Emacs to set evil's initial state to noignorecase -- which doesn't exist, and is not at all what you intended to do.

  • 6
    Note that you can hit M-c during a search to toggle case sensitivity for that invocation of search only. – Tianxiang Xiong Feb 9 '17 at 1:52
  • Setting case-fold-search does not work when doing a search/replace via %s/foo/bar/ – Steven Shaw Dec 10 '18 at 23:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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