Vim Tips Wiki
Advertisement

Previous TipNext Tip

Tip: #72 - Remove unwanted empty lines

Created: June 5, 2001 11:11 Complexity: basic Author: Volker Duetsch Version: 5.7 Karma: 257/125 Imported from: Tip#72

Sometimes to improve the readability of the document I insert empty lines, which will be later removed.

To get rid off them try:

%g/^$/d

This will remove a l l empty line in the document.

Some other tipps you can find under www.linuxclass.de/vim.phtml

Comments

I know this may sound like trolling, but this makes me wonder why there's not an option to rate suggestions "Detremental".

Anonymous , July 13, 2001 20:42


Detrimental? In my opinion tips like these are useful since they show up nicely when you for example google for this little hint you just needed.

Anonymous , January 13, 2004 1:00


This is exactly what I was looking for !

Anonymous , January 9, 2005 15:01


Another way to do it especially if you have spaces or tab characters in your empty lines:

%s/^[\ \t]*\n//g

This pretty much says: replace whole lines that "may" contain spaces or tabs with nothing globally (g). You can add a "c" (for confirm) after the "g" to confirm on every erased line if you don't trust the regexp. Greets, Roumen Semov.

semovrs--AT--concord.edu , March 23, 2005 12:02


Thank you much. This was exactly what I needed to know.

jorge.reyes.spindola--AT--pnl.gov , July 5, 2005 10:34


this was exactly what I was needing. I knew it was something simple; just couldn't remember the exact syntax.

sator at npr dot org , October 12, 2005 8:40


Thanks!

Anonymous , September 3, 2006 23:38


on some machines,

%s/\n\+/\n/g

Anonymous , November 8, 2006 6:28


on some machines,

%s/\n\+/\n/g

replaces all line breaks with a ^--AT--

i can't find the reason (already looked for line break type and encoding)

Ooops--AT--submited.by.mistake , November 8, 2006 6:32


%s/\(\n\)\n\+/\1/g

that works on those machines

Anonymous , November 8, 2006 6:34


Advertisement