How can I stop a c)hange from copying to my paste buffer?

Viewed 109

A common thing I want to do is yank "some text" and then use it to change "some other text".

So I cursor to some text and then yi" to grab the some text. How do I now replace some other text? If I do di" then my copy paste register gets overwritten with some other text. I know I can use named registers, but my problem is my muscle memory has already done yi". Is there any way I can override the default behaviour of either y or d?

2 Answers

"Unnamed" register in Vim is not a real register, but a pointer to a register last used. It's even implemented in Vim's source code as a pointer (or to be more precise, as an index into register array).

So the yanked text does not get really overwritten by "delete" command, as "yank" by default uses register "zero", while "delete" uses either "one" or "minus".

Hence you can always put the last yanked text by pressing "0p.

You could remap the d key to perform a deletion into the blackhole register "_:

nnoremap d "_d

You need to use one of the noremap versions such that it doesn't go into an infinite loop.

Related