paste in visual mode without updating the default register
Vim is great but one thing kept annoying me: when replacing text with the content of my default register, the default register keeps getting updated. That is usually not what I want. What I want is to yank a word to the default register ""
, visually select another word and replace the later with the former.
From the vim docs:
When using a put command like |p| or |P| in Visual mode, Vim will try to
replace the selected text with the contents of the register.
A workaround is to use the "0
register which holds the last yank and is not updated on a paste |p|
in visual mode. But that feels kind of clumpsy.
I found another way to get what I want: Put this into your .vimrc and you will get the desired behavior.
vnoremap p p:let @"=@0<CR></code>
What it does is it simply makes use of the "0
register (holds your last yank) and replaces the content of the default register ""
with the content of the "0
register.