vim FAQ: How do I delete blank lines in vim?
To delete blank lines in vim (empty lines), use this vim last line mode command:
Here's a brief explanation of how this "vim delete blank lines" command works:
:character says "put vim in last-line mode".
gcharacters says "perform the following operation globally in this file".
^$. Here the
^means "beginning of line", and
$means end of line, so with no characters in between them, this vim regex means "blank line". (If I had typed
^abc$, that would mean "find a line with only the sequence of characters "abc".)
dat the end of the command says "When you find this pattern, delete the line".
I hope this vim delete blank lines command example is helpful. If you know of a simpler way to delete blank lines in vim, please leave a comment below.