vim: Can I make *only* y perform a copy?

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.


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.

Tags:

Vim