To delete all blank lines in vim:
:g/^$/d
- “:” -> enter command-line mode
- “g” -> do the action globally (apply it to all lines to which the subsequent match applies)
- “/^$/” -> regex to mean “a line is a match if it contains nothing from start to finish”
- “d” -> the action to do for matches is “delete”
Note: to see the lines which would be deleted without actually deleting them, just remove the action (“d”):
:g/^$/
Of course, you can undo any mistakes with: