13 July 2010

Vim Delete Lines With Regex

To use vim to delete all lines that have a specific string: :g/s1/d. To delete all lines that don't have a specific string, add an exclamation mark before the string: :g!/s1/d. If there are alternative strings to match (logical OR), insert an escaped vertical bar, e.g. :g/s1\|s2/d.