Keep only the lines you need
:v/ERROR/d _
Example
Normal mode. Lines: INFO start, ERROR timeout, INFO retry, ERROR offline.
INFO start
ERROR timeout
INFO retry
ERROR offline- :g/ERROR/p<CR> Preview · ERROR timeout, ERROR offline
- :v/ERROR/d _<CR> Keep the two ERROR lines; delete the rest
ERROR timeout
ERROR offlineDetails & Vim help
Invert :global to operate on lines that do not match.
Extract relevant lines without copying them into another buffer first.
This removes all nonmatching lines in the range, including blank lines. :g!/ERROR/d _ is equivalent.
Try it in Vim
- Inspect :g/ERROR/p to see the lines you will keep.
- Run :v/ERROR/d _.
- Review the reduced buffer before saving.