Friday, May 2, 2008

Remove Empty Lines

Here's a quick sub to remove all the empty lines in a file. I use this to cleanup after macros that leave a bunch of blanks.



RoM said...

Hi !
Your blog is very cool, it made me use H J K and L keys rater than the arrow keys in vim ^^ !

To remove blank lines, you can also do

Since sometimes, \n does not work (I saw that once on AIX with vi)...

Travis Whitton said...

Wow, that's great! Glad you're enjoying the blog and thanks for the tip.

Jadu Saikia said...

Really a nice blog, so much tips about vim, great, thanks.

Outside vim:

$ grep -v '^$' file
$ grep '.' file
$ sed '/^$/d' file
$ sed -n '/^$/!p' file
$ awk NF file
$ awk '/./' file