tags:

views:

1603

answers:

5

What command can I run to remove blank lines in Vim?

+5  A: 

Found it, it's:

g/^\s*$/d
nearly_lunchtime
Nice. But not exactly a blank line.
innaM
Ah, yes, this will match lines containing only whitespace characters. I'll accept soulmerge's answer.
nearly_lunchtime
+19  A: 
:g/^$/d

:g will execute a command on lines which match a regex. The regex is 'blank line' and the command is :d (delete)

soulmerge
+4  A: 
:v/./d

or

:g/^$/d

or

:%!cat -s
mandaleeka
A: 

How about:

:g/^[ \t]*$/d
anon
\s works for tabs too.
Mykola Golubyev
+1  A: 

The following can be used to remove only multi blank lines (reduce them to a single blank line) and leaving single blank lines intact:

:g/^\_$\n\_^$/d
Draemon