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?

1 Answer 1


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


would do the same as your sed command.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .