Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

vim case insensitive search with sensitive replace

Tags:

vim

I have a file with this in it:

test Test 

Currently, if If I want to replace all cases of 'test' with 'foo', and 'Test' with 'Foo', I have to use two commands:

:%s/test/foo/g :%s/Test/Foo/g 

Is there any way that I can accomplish this with a single command?

like image 921
Jimmy Pitts Avatar asked May 28 '12 13:05

Jimmy Pitts


People also ask

How do I search for a word in Vim case-insensitive?

You can use in your vimrc those commands: set ignorecase - All your searches will be case insensitive. set smartcase - Your search will be case sensitive if it contains an uppercase letter.

How do I ignore case-sensitive in Vim?

Searches normally are case-sensitive: a search for "china" will not find "China." If you want vi to ignore case during a search, type :set ic . To change it back to the default, case-sensitive mode, type :set noic .

How do you search for case-insensitive patterns in the open file?

To do a case-insensitive search, go into command mode (press Escape), and type :set ignorecase . You can also type :set ic as an abbreviation.

What is Smartcase in Vim?

Case-insensitive search in Vim. If you want this behavior by default, you can turn on the option: set ignorecase. There's also a so-called "smartcase" ( :help smartcase ) which works as case-insensitive if you only use lowercase letters; otherwise, it will search in case-sensitive mode.


1 Answers

I think this vim plugin by tim pope will solve your problem, install it and %Subvert/{t}est/{f}oo/g or %Subvert/test/foo/g (thanks for the comment) will do the trick

like image 177
epsilonhalbe Avatar answered Sep 21 '22 09:09

epsilonhalbe