Home > Nerdy Stuff > vim: removing blank lines

vim: removing blank lines

This always seems to get me and I have to figure it out every time. Sometimes I have files with blank lines and I want to get rid of them. Here is how you do it in vim (one of the many ways, actually). First you want to get rid of whitespaces:

:%s/^\s\+$//

Note: I used a blockquote here because WordPress doesn’t like two forward slashes in the sourcecode tag.

Then, you have to do this:

:%!grep -v  "^$"

Of course, this only works in Linux, BSD, or any of the other Unices.

Related Posts

Categories: Nerdy Stuff Tags: , , ,
  1. April 8th, 2010 at 17:07 | #1

    Hi,

    Your website is very informative.Keep it up.Good work.

  1. No trackbacks yet.