Skip to content

Vim: delete lines that don’t match pattern

by on January 18th, 2013

Ex command :v to the rescue!


Using :g! will give you the same result as using :v.
:g finds lines that do match a pattern.

I had a large list of locations. I wanted to keep only the locations containing hyphens and delete the rest so I used this: :v/-/d

:v – find lines not matching your pattern
d – delete matches

Recently Loved Articles

From → Vim, Web Development

  1. Dan Herbert AUSTRALIA permalink


    I always forget about that one. I usually do (for your scenario with hyphens):
    :%!grep -v –

Leave a Reply

Note: XHTML is allowed. Your email address will never be published.

Subscribe to this comment feed via RSS