VIM delete all lines not matching pattern

In Vi you can use the following command to search for a pattern and delete all those lines

:%g/pattern-to-search-for/d

To inverse the operation and delete all lines not matching the pattern, change g to v

:%v/pattern-to-search-for/d

Leave a Reply