I want to extract multiple occurences of some text that spans multiple lines and can be matched with a single Vim regex (using meta character \_
).
Unfortunately, althouth the matching lines are properly highlighted in Vim,
when I add any Vim command (like delete or yank) after the matching regexp,
the command only works on the first line of each match.
Example:
1: bad_function(arg1,
2: arg2, arg3,
3: ...
4: argN);
5: good_function();
6: ...
7: bad_function(arg2_1,
8: ...
9: arg2_N);
10: another_good_function();
If I execute :g/bad_function([^;]\+\_[^;]\+;$/d
, then only lines
1 and 7 get deleted although highlighted are lines 1-4 and 7-9.
How to yank/delete all the matched (highlighted) lines?
Try this:
:let @a=''
:g/first\_.*second.*$/normal! v/second^M$"Ay
Enter the ^M
with CTRL-V then Enter.
In order to accumulate matching ranges of lines in a register, one can use the following command.
:let @a='' | g/^first/,/^second/y A
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