I would like to do the inverse operation performed by
:g/pattern/d
i.e Delete all lines in a file which doesn't have pattern
You can use v
to select all line without pattern ::v/pattern/d
will achieve what you want to do.
See :help :v
One way to do this is with a shell filter:
:%!grep pattern
This command passes your whole file (%
) to a shell (!
) which runs it through the grep pattern
command and returns the output to your editor window.
You can simply negate the pattern
:g!/pattern/d
This will delete all but the selected 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