Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vim delete blank lines

Tags:

vim

vi

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

like image 574
nearly_lunchtime Avatar asked Apr 01 '09 15:04

nearly_lunchtime


People also ask

How do I delete all blank lines?

Click “Home” in the menu and then select “Replace” on the right of the screen. Then click “Replace All” at the bottom of the window. After you click, all the blank lines will be removed from your document. When you see the confirmation pop-up, click “OK.”

How do I remove blank lines in Linux?

Delete blank lines using the grep command When used with the -v option, the grep command helps to remove blank lines. Below is a sample text file, sample. txt, with alternative non-empty and empty lines. To remove or delete all the empty lines in the sample text file, use the grep command as shown.


1 Answers

:g/^$/d 

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

like image 115
soulmerge Avatar answered Nov 03 '22 17:11

soulmerge