Saari Development

Vim: Delete every line in the file that does not match a pattern

Posted in editor by imsaar on September 25th, 2007

I realized the power of :g much later than many other commands in vim and I think this one has been there even in vi for a long time.

Here is a great tip that covers the virtues of :g in vim:

Tip #227: Power of :g

The reason I ended up with this tip was that I needed to find a simple command that would delete all lines matching a pattern.

I knew how to delete all lines that matched a pattern.

:g/pattern/d

but I was looking for the inverse and I found it :g’s cousin :v in the above tip as a user comment.

:v/patter/d

did the job very well. Once again vim saved the day. :-)

*nix: nslookup to resolve an IP to host name

Posted in linux/unix by imsaar on September 13th, 2007

nslookup is useful to resolve an ip address to a host name in the linux/unix environment.

nslookup - query Internet name servers interactively