I always wanted to know, how you can substitute within given parameters.
If you have a line like this:
123,Hello,World,(I am, here), unknown
and you wnat to replace World with Foobar then this is an easy task: :%s/World/Foobar/
Now I wonder how I can get rid of a , which is wihtin the ( ).
Theoretically I just have to find the first occurance of ( then substitute the , with a blank until ).
Try lookahead and lookbehind assertions:
(
\zsand\zetell where pattern starts and end)or
The first one is more readable, the second one uses
\( ... \)groupings with parentheses inside groups which makes it look like obfuscated, and\@<=which apart from being a nice ASCII-art duck is the lookbehind operator, and\@=that is the lookahead operator.References:
:help pattern(more detail at:help /\@=,:help /\ze, etc.)You use the GUI and want to try those commands? Copy them into the clipboard and run
:@+inside Gvim.