I'd like to search for an upper case word, for example COPYRIGHT in a file. I tried performing a search like:
/copyright/i # Doesn't work
but it doesn't work. I know that in Perl, if I give the i
flag into a regex it will turn the regex into a case-insensitive regex. It seems that Vim has its own way to indicate a case-insensitive regex.
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.
Also,
\c
can appear anywhere in the pattern, so if you type a pattern and then decide you wanted a case-insensitive search, just add a\c
at the end.I like to add
set ignorecase
for case-insensitive searching in my vimrc, and I can use\C
to do a case-sensitive search similar to what @AlokSinghal mentioned.There's also
set smartcase
which will automatically switch to a case-sensitive search if you use any capital letters.Just want to add to Zaz's comment.
set smartcase
applies only whenset ignorecase
is already active. I was stumped on this for a while. See Vim Tips.@coderMe, It's the capitalization,
\c
versus\C