Wikia

Vim Tips Wiki

Remembering previous deletes/yanks

Talk0
1,613pages on
this wiki
Revision as of 05:50, July 13, 2012 by JohnBot (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
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.

RegistersEdit

CommentsEdit

This is pretty magic as well:

"1p....

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


This is called yank-pop in emacs, it is very useful.

Emacs has unlimited depth for yank-pop, and it will cycle thru the list when pasting.

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 emacs' M-y).


Around Wikia's network

Random Wiki