How To Delete Blank Lines In Vim

By admin ·
1

:g/^$/d

While in normal mode, type:

:g/^$/d

Here’s a breakdown of this command.

Description
:g This will execute a command globally on all lines that match a regex (to follow).
/^$/ This is the regex. The forward slashes enclose the pattern, which is: ^$. This is a regex pattern that matches the beginning of a line (^) and the end of a line ($) with nothing in between, which is the definition of a blank line 🙂
d This is the command to be executed. d stands for delete!

So when you put it all together, you find all blank lines globally across the whole file, and delete them.

2

:g/^$/d

While in normal mode, type:

:g/^$/d

Here’s a breakdown of this command.

Description
:g This will execute a command globally on all lines that match a regex (to follow).
/^$/ This is the regex. The forward slashes enclose the pattern, which is: ^$. This is a regex pattern that matches the beginning of a line (^) and the end of a line ($) with nothing in between, which is the definition of a blank line 🙂
d This is the command to be executed. d stands for delete!

So when you put it all together, you find all blank lines globally across the whole file, and delete them.

3

:g/^$/d

While in normal mode, type:

:g/^$/d

Here’s a breakdown of this command.

Description
:g This will execute a command globally on all lines that match a regex (to follow).
/^$/ This is the regex. The forward slashes enclose the pattern, which is: ^$. This is a regex pattern that matches the beginning of a line (^) and the end of a line ($) with nothing in between, which is the definition of a blank line 🙂
d This is the command to be executed. d stands for delete!

So when you put it all together, you find all blank lines globally across the whole file, and delete them.

4

:g/^$/d

While in normal mode, type:

:g/^$/d

Here’s a breakdown of this command.

Description
:g This will execute a command globally on all lines that match a regex (to follow).
/^$/ This is the regex. The forward slashes enclose the pattern, which is: ^$. This is a regex pattern that matches the beginning of a line (^) and the end of a line ($) with nothing in between, which is the definition of a blank line 🙂
d This is the command to be executed. d stands for delete!

So when you put it all together, you find all blank lines globally across the whole file, and delete them.

5

:g/^$/d

While in normal mode, type:

:g/^$/d

Here’s a breakdown of this command.

Description
:g This will execute a command globally on all lines that match a regex (to follow).
/^$/ This is the regex. The forward slashes enclose the pattern, which is: ^$. This is a regex pattern that matches the beginning of a line (^) and the end of a line ($) with nothing in between, which is the definition of a blank line 🙂
d This is the command to be executed. d stands for delete!

So when you put it all together, you find all blank lines globally across the whole file, and delete them.

6

:g/^$/d

While in normal mode, type:

:g/^$/d

Here’s a breakdown of this command.

Description
:g This will execute a command globally on all lines that match a regex (to follow).
/^$/ This is the regex. The forward slashes enclose the pattern, which is: ^$. This is a regex pattern that matches the beginning of a line (^) and the end of a line ($) with nothing in between, which is the definition of a blank line 🙂
d This is the command to be executed. d stands for delete!

So when you put it all together, you find all blank lines globally across the whole file, and delete them.

7

:g/^$/d