3 Ways of Making Case Insensitive Search in Vim/Vi

By default, Vim/Vi’s search is case sensitive. However, if I want to search case insensitively, is there any method?

For example, I search for dog, instead of dog, I also want to find out phases containing Dog, DOg, etc.

There are several methods:

1. Setting the search to be case insensitive in Vim

:set ignorecase

To unset it:

:set noignorecase

You can also put it to your .vimrc if you want the behavior to be the default one.

2. You can also force a pattern to be case insensitive or sensitive by \c or \C regardless the setting of ignorecase.

For example, the search /dog\c is always case insensitive. And /dog\C is always case sensitive.

3. Use smartcase

To enable it:

:set smartcase

If your search pattern is purely lowercase, it will search case insensitively.
If your search pattern contains uppercase characters, it will search case sensitively.

2 comments:

  1. The second method above is incorrectly stated and should read (see vim ‘:help /\c’):
    2. You can also force a patten to be case insensitive or sensitive by \c or \C regardless the setting of ignorecase.

    For example, the search /dog\c is always case insensitive. And /dog\C is always case sensitive.

Leave a Reply

Your email address will not be published. Required fields are marked *