Wiki

by yszheda

View project onGitHub

Tip 98: Delete Lines Containing a Pattern

Return to the top: <<Practical Vim>>

On the Etymology of Grep

abbreviated form of the :global command:

:g/re/p
  • re: regular expression
  • p: :print

Delete Matching Lines with :g/re/d

Example: throw away everything except for the contents of each <a> tag:

/\v\<\/?\w+>
:g//d

Keep Only Matching Lines with :v/re/d

Example: Delete each line that doesn’t contain href:

:v/href/d