vim Whitespace Delete blank lines in a file


Example

You can delete all blank lines in a file with the following command: :g/^$/d

This command is explained as follows:

  • enter Command mode with :
  • g is a global command that should occur on the entire file
  • / start of the search pattern
  • the search pattern of blank line is ^g
  • /end of the search pattern
  • Ex command d deletes a line