Skip to content

Instantly share code, notes, and snippets.

@hectorperez
Last active August 29, 2015 14:02
Show Gist options
  • Save hectorperez/056967d96e09481fb40e to your computer and use it in GitHub Desktop.
Save hectorperez/056967d96e09481fb40e to your computer and use it in GitHub Desktop.
Delete all lines containing a pattern in Vim
# to delete all lines containing "profile" (remove the /d to show the lines that the command will delete):
:g/profile/d
# to delete all lines that do not contain a pattern, use 'g!' (equivalent to 'v'), like this command to delete all lines that are not comment lines in a Vim script:
:g!/^\s*"/d
:v/^\s*"/d
# to delete all lines except those that contain "error" or "warn" or "fail"
:v/error\|warn\|fail/d
# http://vim.wikia.com/wiki/Delete_all_lines_containing_a_pattern
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment