Monday, November 16, 2009

case insensitive / Ignore case in vim searches

case insensitive / Ignore case in vim searches

Ahhh, there it is! I've often wanted to know how to make "/" searches in vim case insensitive, and today somebody at work enlightened me. 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

/\croot

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

John said...

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.

:set ignorecase
:set smartcase

":help set" will tell you all about the :set command, including :set no{command} to unset a boolean, and even :set {command}! which toggles it

You can also toggle the setting with :set ignorecase! and query its value with :set ignorecase?

Pay attention to 'smartcase' option. It overrides the 'ignorecase' option if the search pattern contains upper case characters.

i.e. having 'ignorecase' and 'smartcase' on /foo will find foo, Foo and FOO, but /Foo will find only Foo, not foo.

You can also tell Vim that you want to search case-sensitive despite of 'ignorecase' setting by using \C somewhere in the search pattern. By using \c in the search pattern you tell Vim to ignore case while searching, despite of 'ignorecase' setting.

Reference:
http://stackoverflow.com/questions/452649/unset-ignorecase-in-vim

No comments: