Reputation: 18147
I find fatal errors in my ansible log and copy them to end of file to see all the fatal errors.
:g/fatal:/t$
But I would like to copy error and next line ,because next line some time would be 'ignoring' which need not to be considered. I can find only real fatal errors which is required
How to move pattern and few more lines? In grep we can find -A -B ,is there any way in g command to do it?
Upvotes: 1
Views: 73
Reputation: 11435
Edit: @romainl's answer is strictly better and should be preferred for what OP is trying to do.
If all you're trying to do is copy the line containing "fatal:" and a couple of lines afterward, you can do:
/fatal:<CR>y<motion>
, where <CR>
is Enter and <motion>
can be, for example, 2j
for "this line and the next line" or G
for "from this line to the end of the file", etc.
Upvotes: 0
Reputation: 196556
Like all ex commands inherited from vi
and ex
, :help :t
can take a :help :range
. In this case, you want to operate on the matching line and the line below, which translates to the following range:
.,+1
where:
.
represents the current line,+1
represents the line below the current line,which gives you this command:
:g/fatal:/.,+1t$
Note that .
is implied and +
is a shortcut for +1
, so it can be shortened to:
:g/fatal:/,+t$
Upvotes: 6