I decided that I have to get rid of a couple of annoying things which decrease my productivity in Vim. I know they must have a simple solution.

So, my first question:

If I copy a word in clipboard using yw for example, and I want to copy this word to some other spot (or, very often, more spots), but meanwhile I have to delete something and I use x or dw, the clipboard is overwritten, and I am not able to finish the task I intended. I could enter the insert mode and use delete key but that is of course too much work. How do you behave in this situation and what strategy do you use?


1 Answer 1


For the case of yanking one thing, deleting others, then pasting the yanked text instead of deleted text, I use the last-yanked register.

from :help "0:

Vim fills these registers with text from yank and delete commands. Numbered register 0 contains the text from the most recent yank command, unless the command specified another register with ["x]. Numbered register 1 contains the text deleted by the most recent delete or change command, unless the command specified another register or the text is less than one line (the small delete register is used then). An exception is made for the delete operator with these movement commands: %, (, ), `, /, ?, n, N, { and }. Register "1 is always used then (this is Vi compatible).

So, after yw and then some dw (or whatever), I can paste the yanked text with "0p

For more complicated tasks (deleting multiple things and pasting the different multiple things) I either anticipate ahead of time and use named registers (e.g. "adw), or check the contents of the numbered registers after the deletions to see which ones have what I want to paste, using :registers, which might show something like

"0   char *^J
"1   ^I^I^Iint utf8flag = 1;^J
"2   ^Istruct window^I^I*w^J

If I want the struct window line, I'd then do "2p

Not the answer you're looking for? Browse other questions tagged or ask your own question.