Vim Recall繁體中文

Keep only the lines you need

:v/ERROR/d _

Example

Normal mode. Lines: INFO start, ERROR timeout, INFO retry, ERROR offline.

Before
INFO start
ERROR timeout
INFO retry
ERROR offline
  1. :g/ERROR/p<CR> Preview · ERROR timeout, ERROR offline
  2. :v/ERROR/d _<CR> Keep the two ERROR lines; delete the rest
After
ERROR timeout
ERROR offline
Details & 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

  1. Inspect :g/ERROR/p to see the lines you will keep.
  2. Run :v/ERROR/d _.
  3. Review the reduced buffer before saving.