With insertions, it is very easy to both wipe out a word/section and insert over it, like so
cw
delete until end of word (with space) then go to insert modece
delete until end of word (without space) then go to insert modec3w
delete until end of the next 3 words (with space) then go to insert modect.
delete until before period then go to insert modec$
delete until end of line then go to insert modeHow do I do this with paste operations? Often times I have a line like so
var name = "John Smith"
var name = "Jane Smith"
And I change it to
var name = "John Lee"
var name = "Jane Smith"
And yank (yw
) "Lee", but now if I delete (dw
) "Smith" from "Jane Smith", I no longer have "Lee" in the register to paste back. I know I can use the named registers. Also, I am sure I can use visual mode. However, I figured since this is a pretty common task, there would be a way to use the movement operators (e
, w
, t
/T
, f
/F
,$
,0
) with the paste command to specify what to paste over.
I think visual mode is the way to go. You just enable visual mode with v or V (if you want to overwrite whole lines at the time), use the movement operators in the usual way to select the area to be replaced and then paste. You take advantage of what you already know.
Vp overwrites the current line. vwp overwrites the current word.
You can find an overview of the alternatives at the Vim Wikia.
Oh yes, what you want is the ultra convenient (sarcasm) blackhole register: select in visual mode the part you want to replace, using the movement you want (like vw
), then "_xP.
The black hole register _
is a special register akin to /dev/null
. The operation "
sets the destination register for the text you are about to replace, and thus "_
ensures that the unwanted "Smith" hits the blackhole register. Thus, "Lee" is preserved in the "
register. I'd recommend using macros to help if you're doing this many times in a row.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With