created February 10, 2002 · complexity basic · author tarjei · version 5.7
The ex command, 'g' is very useful for acting on lines that match a pattern. You can use it with the ex command, 'd' to delete all lines that contain/do not contain a particular pattern.
For a trivial example, delete all lines containing "profile":
Obviously, more complex patterns can be used, such as deleting all lines that are empty or contain only whitespace:
Finally, to delete all lines that do NOT contain a pattern, use g!, like this command to delete all lines that are not comment lines in a Vim script:
Note that the 'g!' command is equivalent to the 'v' command, so you could also do the above with: