• Wincent
    Open
  • Blog
  • Wiki
  • Snippets
  • Tags
  • Search

Delete lines matching a pattern in VimEdit

Created 2/1/2011, updated 5/18/2017

Deleting matching lines

For example, to delete all lines starting with a # (ie. Ruby comments starting in column 0):

:g/^#/d

Deleting non-matching lines

To delete non-matching lines we substitute g! or v for g:

:g!/^#/d

Or:

:v/^#/d

See also

  • http://vim.wikia.com/wiki/Delete_all_lines_containing_a_pattern
  • vim
  • recipe
  • wiki
Site
  • About
  • Blog
  • Wiki
  • Snippets
  • Tags
  • Search
External
  • GitHub
  • Twitter
  • YouTube
  • Facebook
  • LinkedIn
Colophon

Made by Greg Hurrell using React, Relay and GraphQL (with help from Git, Redis and Neovim).