The Learn Emacs Twitter feed has a handy tip for dealing with blank lines:
Making & Deleting blank lines:
If your point/cursor lies within several blank lines C-x C-o will delete all but one blank line, another C-x C-o will delete that last empty line.
C-o will insert a new blank line but leave your point before the newlines.#emacs
— learn emacs (@learnemacs) March 19, 2019
It turns out that the delete-blank-lines
command is a little more nuanced than that. The actual rules for invoking it (according to the documentation) are:
- If the point is on a blank line surrounded by others, delete all the surrounding blank lines, leaving just one.
- If the point is on an isolated blank line, delete that line.
- If the point is on a nonblank line, delete any blank lines that immediately follow.
This isn’t a command that I’d use everyday but it seems perfect for cleaning up a text file with lots of blank lines. Often times, I see imported data like this so it’s worth remembering the command.