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 Answers 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.

  • 7
    Note that you can hit M-c during a search to toggle case sensitivity for that invocation of search only. Feb 9, 2017 at 1:52
  • 2
    Setting case-fold-search does not work when doing a search/replace via %s/foo/bar/ Dec 10, 2018 at 23:52
  • 1
    For search and replace use (setq evil-ex-search-case nil). Jan 24, 2021 at 20:47

Dan's answer was the solution in my case. Nevertheless, I also had to set the variable as default in my init.el in order to work:

(setq-default case-fold-search nil)

If you just want to change to case-insensitive search for the current search session only, C-o in the search minibuffer to invoke the hydra interface, and C-c to toggle case sensitivity.

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.