Thursday, September 29, 2011

Deleting all lines that are empty or contain spaces in vim

To delete all lines that are empty in vim:

:g/^$/d

To delete all empty lines or empty lines that contain spaces:

:g/^\s*$/d

Note that \s represents the space character in the regular expression. Or simply, you can also represent the space character with [ ]:

:g/^[ ]*$/d

No comments: