Vi(m) tip #1: delete, yank and change until regex
Alec Jacobson
October 14, 2009
I think I'm going to start posting all the neat vi/vim tips I find on the web. Probably none of them will be original, but perhaps the redundancy of my posting them here with perhaps more context will be of use. And I'll create a little archive of what I should remember how to do.
In normal mode, you can delete, yank and change until you hit a specified regex (regular expression)
d/pattern/
will delete everything in between the cursor and the next occurrence of "pattern".
Likewise
y/pattern/
will yank everything in between the cursor and the next occurrence of "pattern".
Lastly,
c/pattern/
will change everything in between the cursor and the next occurrence of "pattern". Here, change means that everything in between the cursor and the next occurrence of "pattern" will be deleted and then you will enter insert mode.
Adding e
as in,
c/pattern/e
will delete the next occurrence of "pattern" in addition to the stuff in between.
source of tip