RSS

[vim] Delete blank lines

26 Aug

Here are two ways to delete the blank lines in a text file opened with vim:

1. Delete all the blank lines with NO white spaces other than new lines:

:g/^$/d

2. Delete the blank lines containing any type of white spaces:

:g/^\s*$/d

BONUS: Remove only multi blank lines (reduce them to a single blank line) and leaving single blank lines intact:

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

Reference: Stack Overflow.

About these ads
 
Leave a comment

Posted by on August 26, 2013 in vim

 

Tags: , , , , , , ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
Follow

Get every new post delivered to your Inbox.

Join 32 other followers

%d bloggers like this: