How to do case insensitive search in Vim

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 need to use the c escape sequence. So:

/ccopyright

To do the inverse (case sensitive matching), use C instead.


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 ignorecase
:set smartcase
/copyright      " Case insensitive
/Copyright      " Case sensitive
/copyrightC    " Case sensitive
/Copyrightc    " Case insensitive

See:

:help /c
:help /C
:help 'smartcase'

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

链接地址: http://www.djcxy.com/p/1378.html

上一篇: 将文本粘贴到vim时关闭自动缩进

下一篇: 如何在Vim中进行不区分大小写的搜索