How to do case insensitive search in Vim
Solution 1:
You can use the \c
escape sequence anywhere in the pattern. For example:
/\ccopyright
or /copyright\c
or even /copyri\cght
To do the inverse (case sensitive matching), use \C
(capital C) instead.
Solution 2:
As well as the suggestions for \c
and ignorecase
, I find the smartcase
very useful. If you search for something containing uppercase characters, it will do a case sensitive search; if you search for something purely lowercase, it will do a case insensitive search. You can use \c
and \C
to override this:
:set ignorecase
:set smartcase
/copyright " Case insensitive
/Copyright " Case sensitive
/copyright\C " Case sensitive
/Copyright\c " Case insensitive
See:
:help /\c
:help /\C
:help 'smartcase'
Solution 3:
You can set the ic
option in Vim before the search:
:set ic
To go back to case-sensitive searches use:
:set noic
ic
is shorthand for ignorecase
Solution 4:
You can issue the command
:set ignorecase
and after that your searches will be case-insensitive.
Solution 5:
To switch between case sensitive and insensitive search I use this mapping in my .vimrc
nmap <F9> :set ignorecase! ignorecase?