I use the following VIM command, to copy all lines including a pattern to the end of the file
:g/pattern/t$
But I also want the previous or the line below of the matched line copied too
In:
:g/pattern/t$
:t is an ex command which, like all ex commands, can take a range.
The following command would copy lines 1-13 after the last line:
:1,13t$
Beside absolute line numbers, you can use relative numbers:
:-3,+5t$
and, really, anything that can be translated to a line number:
:?foo?,'et$
In your case, you can use a range to tell Vim to copy the marked line, the one above (-1), and the one below (+1):
:g/pattern/-1,+1t$
Or, slightly shorter:
:g/pattern/-,+t$
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