Wednesday, August 31, 2011

Vim search string case insensitive

Vim search string case insensitive

If \c appears anywhere in a pattern the whole pattern is assumed to be case insensitive. So to search for the string "root" while ignoring case you'd use




Take a look at :help ignorecase in vim for more info.

I use the ignorecase and smartcase settings as default, and they work great for me. Any search with an uppercase character becomes a case sensitive search.

\c is good to know when your working on other people's stations.

To ignore case in the searches, enter the following command:
:set ignorecase
:set ic

To turn on smartcase:
:set scs

This command can be abbreviated :set ic. To turn off this feature, use:

:set noignorecase


If you want to ignore case for one specific pattern, you can do this by
prepending the "\c" string. Using "\C" will make the pattern to match case.
This overrules the 'ignorecase' and 'smartcase' options, when "\c" or "\C" is
used their value doesn't matter.

pattern matches ~
\Cword word
\CWord Word
\cword word, Word, WORD, WoRd, etc.
\cWord word, Word, WORD, WoRd, etc.

A big advantage of using "\c" and "\C" is that it sticks with the pattern.
Thus if you repeat a pattern from the search history, the same will happen, no
matter if 'ignorecase' or 'smartcase' was changed.


No comments: