Wikia

Vim Tips Wiki

Changes: Remembering previous deletes/yanks

Edit

Back to page

(Adjust previous/next navigation + minor manual clean)
(Change <tt> to <code>, perhaps also minor tweak.)
 
Line 12: Line 12:
 
|category2=
 
|category2=
 
}}
 
}}
Say you delete a paragraph with the command <tt>d}</tt> and you intend to paste that paragraph into another file.
+
Say you delete a paragraph with the command <code>d}</code> and you intend to paste that paragraph into another file.
   
So you edit the other file with <tt>:e other.txt</tt> and you scroll down to where you want to paste the original paragraph. But then you accidentally delete or yank some text.
+
So you edit the other file with <code>:e other.txt</code> and you scroll down to where you want to paste the original paragraph. But then you accidentally delete or yank some text.
   
Now typing <tt>p</tt> simply pastes the text that you just deleted or yanked.
+
Now typing <code>p</code> 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 <tt>:reg</tt> to list all the registers.
+
Fortunately, Vim remembers previous deletes/yanks in the numbered registers. You can enter the command <code>:reg</code> to list all the registers.
   
If the text you want is in register 2, enter <tt>"2p</tt> to paste it after the cursor, or <tt>"2P</tt> to paste it before the cursor.
+
If the text you want is in register 2, enter <code>"2p</code> to paste it after the cursor, or <code>"2P</code> to paste it before the cursor.
   
 
Small deletes (less than a complete line) do not fill the numbered registers.
 
Small deletes (less than a complete line) do not fill the numbered registers.
Line 43: Line 43:
   
 
----
 
----
After doing a <tt>"1p</tt> you can also cycle through the numbered registers by doing <tt>u.</tt> repeatedly (i.e. remove the last paste and paste the next numbered register, much like emacs' M-y).
+
After doing a <code>"1p</code> you can also cycle through the numbered registers by doing <code>u.</code> repeatedly (i.e. remove the last paste and paste the next numbered register, much like emacs' M-y).
   
 
----
 
----

Latest revision as of 05:50, July 13, 2012

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