Home » Questions » Computers [ Ask a new question ]

Is there an opposite of :g in vim?

Is there an opposite of :g in vim?

I know how to do something to every line that matches a pattern, using :g. Is there a way to do something to every line that does not match the pattern?

Asked by: Guest | Views: 39
Total answers/comments: 1
Guest [Entry]

"I think there is a inversion within VIM as,

:g!/foo/d

or, like the grep command (below),

:v/foo/d

If you are ready to go to the shell prompt,

grep -v foo filename.txt > new.txt

will do this"