I need to figure out a regular expression to delete all lines that do not begin with either "+" or "-".
I want to print a paper copy of a large diff file, but it shows 5 or so lines before and after the actual diff.
The ex command g is very useful for acting on lines that match a pattern. You can use it with the d command, to delete all lines that contain a particular pattern, or all lines that do not contain a pattern.
In VIM:
:g!/^[+-]/d
Here is the English translation:
g
lobally do something to all lines that do NOT!
match the regular expression: start of line^
followed by either +
or -
, and that something to do is to d
elete those lines.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With