tags:

views:

341

answers:

5

I'd like to search a upper case word, for example COPYRIGHT in a file . then I try to do the search like:

/copyright/i

but it doesn't work. I know in Perl if give the i flag into a regex it will turn the regex to a case-insensitive regex. Seems that Vim has its own way to indicate a case-insensitive regex.

+16  A: 

You need to use the \c escape sequence. So:

/\ccopyright

Chinmay Kanchi
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.
Alok
I didn't know that! Very useful...
Chinmay Kanchi
+4  A: 

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

Nathan Fellman
+6  A: 

You can issue the command

:set ignorecase

and after that your searches will be case-insensitive.

Paolo Tedesco
+6  A: 

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 smartcase
/copyright      " Case insensitive
/Copyright      " Case sensitive
/copyright\C    " Case sensitive
/Copyright\c    " Case insensitive

See:

:help /\c
:help /\C
:help 'smartcase'
Al
A: 

To switch between case sensitive and insensitive search I use this mapping in my .vimrc

nmap <F9> :set ignorecase! ignorecase?

vbd