Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

vim

I know how to copy a word, but I seem to overwrite what is in my clipboard because, when I try to copy over a word, it does not seem to be working.

To copy a word, I can use

bye

How to copy over a word?

like image 471
codecompleting Avatar asked Oct 17 '11 17:10

codecompleting


People also ask

How do I copy text and paste outside in Vim?

To copy selected text to system clipboard type "+y in Normal Mode. Now you can paste it anywhere else using Ctrl-v . To copy text from outside applications into Vim editor, first copy the text using the usual Ctrl-C command then go to Vim editor and type "+p in Normal Mode.


2 Answers

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
like image 125
Benoit Avatar answered Oct 19 '22 22:10

Benoit


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.

like image 27
ib. Avatar answered Oct 19 '22 23:10

ib.