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?
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.
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 .
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With