Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to save complex grep output in gvim

Tags:

grep

vim

In my gvim file I have something like below

Before line
name1/name2/name3/
next line

name2/name3 is the pattern of my interest.

I want to delete the line containing the pattern and the next line of matched pattern.

I want to save the both lines in other file. I am able to search and delete the lines using global

:g/name2\/name3/,+1d

but not able to redirect it into other file.

How can I save the grep output to some other file.

like image 410
user2728477 Avatar asked Feb 18 '26 02:02

user2728477


1 Answers

You can use write >> f to append to the file f (or write! >> f if you want to create f if it doesn't exist).

:g/name2\/name3/,+ write! >> f | ,+d 

Alternatively you could use :redir >> (which avoids repeating the ,+ range) :

:g/name2\/name3/,+1d | redir! >> f | silent echon @" | redir END
like image 166
Marth Avatar answered Feb 19 '26 15:02

Marth



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!