The ex command :g -global command, is very useful for acting on lines that match a pattern.

Usually it works like this:


Delete contains

To delete all lines that contain “price” you can use:


If you want to use multiple pattern you can use ‘or’ \|:


Delete not contains

To delete lines that does NOT contain “price” you can use:


~Some extras

Delete all empty lines


Or deleting all lines that are empty or that contain only whitespace:


Trim all whitespaces at the end of a line

Deletes any trailing whitespace at the end of each line. If no trailing whitespace is found nothing changes, and the e flag means no error is displayed. Since if nothings is found E486: Pattern not found error occurs.


Delete commented lines

:g/^<language comment string>/d

E.g for python:


All done!