1

I'm comfortable doing search/replace in vim, but how do I delete all lines in a file (or between certain lines) if they match a condition? Currently I shell out and run a sed command, for example:

sed -i '/^CRITICAL/d' hosts

(delete all the lines that start with CRITICAL from the hosts file).

How would I do this in vim?

6

I guess the best way would be to use the ex command g.

:g/^CRITICAL/d

would do the same as your sed command.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.