Hide all (not)matching lines in Vim

Alex Bolotov picture Alex Bolotov · May 14, 2009 · Viewed 52k times · Source

Is it possible to show/hide all matching lines in vi or Vim? Not highlight but just show only those lines.

For example I have a text with word the word ERROR. How do I make it show only lines containing ERROR and how to show only lines without ERROR?

Is there a solution without deleting all matching lines and then just undoing it?

Answer

user55400 picture user55400 · May 14, 2009

Do you know about the :global command? Does this do what you want?

:g/ERROR

and for the opposite:

:g!/Error

or equivalently:

:v/Error