I'm learning to like vim, but one thing that I haven't yet fully embraced is the copy and paste situation. In a muggle text editor I would Ctrl-C copy a piece of text and then edit/delete and then paste the text somewhere else. However in vim I can't do this because after I copy text with y, modifying the text often involves d and x which obliterates my original text.

Is there any way to make d and x not copy the text? Or otherwise, how should I be using these vim features?

4 Answers 4


The 9 previous yanks are saved in registers called 1 through 9. You can recall the next-to-last yank with "1p, the previous one with "2p and so on. The command :reg shows the registers that are available for pasting.

If you want a yank to last longer, use a letter register.

For the more obscure yank-related commands, start reading at :help " in the manual.

  • 2
    Also, register 0 contains the last text yanked (as opposed to deleted). So referring back to the original question, you can yank with y, continue editing including d and x, and paste the yanked text in with "0p
    – Nefrubyr
    May 16, 2012 at 9:15
  • @Nefrubyr, your comment above is actually the simplest answer, but it's not mentioned in any of the existing three answers. Perhaps you should add it? (I may if you don't.)
    – Wildcard
    Apr 29, 2016 at 20:34

The commands you're talking about use the so-called "unnamed" register. It is meant only for very short term use. "I'm gonna yank this from here and put it over there" sort of things.

When you want to hold onto something for more than a few seconds while you go and do something else, you should be using named registers.

For instance, " a y y will yank the line the cursor is on into the a register. Nothing will clobber it accidentally, unless you type another command involving the a register. Minutes, hours, even days later, you can type " a p to drop that yanked copy of the line from the a register below the one the cursor is on.

(For this to work really well, you should have a line like set viminfo='50,\"1000 in your ~/.vimrc file, to tell it to remember things like register contents across Vim sessions. You can then go on vacation between yank and put!)

There are 26 named registers (a-z). If you give them as uppercase instead of as shown above, you append to the current register contents instead of replacing them. So, you can build up something really complex in, say, register h one piece at a time, then plop it all down at once with " h p.

Notice that the register name is optional. This implies that there may be many commands you already know and use where you could be using named registers. Say :help registers in Vim to get some idea of the possibilities.

Also, get a Vi mug.


If you need to delete text with d without altering your yank register (say, you've already yanked text in it that you're not ready to paste before your delete some other text for instance), you can use the black hole register _.

If you do "_dd for example, the current line will be immediately deleted and forgotten.

Actually, I don't use this register very often. It doesn't take less keystrokes than saving to a general-purpose register (any letter register) and if you save to a general-purpose register, at least, the lines that you have deleted are still available until you overwrite the register, if the need arises.

If you tend to forget to use another register when deleting, you can define a wrapper macro for dd for instance like this: :noremap dd "add.


As was pointed out in the comments to the (current) accepted answer, the canonical way to do this is to use register zero ("0). Register zero always contains the last yank, and will not get overwritten by d and x, so "0p always puts whatever you yanked regardless of what's been edited in the meantime.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .