Nathan's Blog

Web development and useful information

Vim: delete lines that don’t match pattern

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


Unit test private methods in PHP


How to protect your HSBC Secure Key


  1. Dan Herbert


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

Leave a Reply

Powered by WordPress & Theme by Anders Norén