How to copy a word and paste it over another word in Vim?

Copy the source word as usual (e.g., with yiw) and use

viw"0p

to paste over the destination word.

Since the p command in Visual mode (see :help v_p) does not alter the numbered register 0 containing the text from the most recent yank command, the same copied word can be pasted over and over again.


Perhaps you just want to do this:

viwp

which will visually select a new word, and paste over it.

Now, if you don't want to lose your register when doing this, you can also put in your vimrc:

xnoremap p pgvy

Tags:

Vim