My document looks something like this:
Line number one
Line number two
Line number three
I want the whole document to look like this:
Line number one
Line number two
Line number three
In other words, to remove all the empty lines. How to accomplish this?
Try
:g/^$/d, which will remove all blank lines. Thegindicatesglobal, the^$is a regular expression that basically means ‘match lines that start and end with nothing in between’, and thedmeansdelete. You can mix and match as much as you need 🙂Another space-related command that may come in handy if you have random whitespace is
:%s/\s\+$//, which trims any trailing whitespace (as @Bernhard points out, the$operator means that you have a max of one occurrence per line, so thegis unnecessary).Per the update, possible that the lines already contain whitespace, in which case
:g/^\s*$/dshould work.