Vim Tips Wiki
Register
Advertisement
Tip 832 Printable Monobook Previous Next

created 2004 · complexity basic · author Rory McCann · version 5.7


Say you delete a paragraph with the command d} and you intend to paste that paragraph into another file.

So you edit the other file with :e other.txt and you scroll down to where you want to paste the original paragraph. But then you accidentally delete or yank some text.

Now typing p simply pastes the text that you just deleted or yanked.

Fortunately, Vim remembers previous deletes/yanks in the numbered registers. You can enter the command :reg to list all the registers.

If the text you want is in register 2, enter "2p to paste it after the cursor, or "2P to paste it before the cursor.

Small deletes (less than a complete line) do not fill the numbered registers.

Registers[]

Comments[]

This is pretty magic as well:

"1p....

put each numeric register successively (where the dot is the Vim repeat operator).


This is very useful.

Somewhat similar to the "kill ring" in Emacs, where the number of items retained is arbitrary (configurable). However, in Vim it is limited to 10 registers and not intuitive.


After doing a "1p you can also cycle through the numbered registers by doing u. repeatedly (i.e. remove the last paste and paste the next numbered register, much like "yank-pop" in Emacs: M-y). See :help redo-register for further Information


Advertisement