vim – delete all blank lines

To delete all blank lines in vim:

  •  “:” -> 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”):


Of course, you can undo any mistakes with: ESC then u

Sharing is caring!

Leave a Comment

Your email address will not be published. Required fields are marked *

Notice: Undefined index: total_count_position in /var/www/wordpress/wp-content/plugins/social-pug/inc/functions-frontend.php on line 46