Vim Tips Wiki
mNo edit summary
 
(Added little information about the repeat (.) command)
Tags: Visual edit apiedit
(5 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 
 
{{review}}
 
{{review}}
  +
{{TipImported
{{Tip
 
 
|id=832
 
|id=832
|title=Remembering previous deletes/yanks
+
|previous=830
  +
|next=834
|created=December 10, 2004 13:12
+
|created=2004
 
|complexity=basic
 
|complexity=basic
|author=Kevin Lyda, added by Rory McCann
+
|author=Rory McCann
 
|version=5.7
 
|version=5.7
 
|rating=62/26
 
|rating=62/26
  +
|category1=
|text=
 
  +
|category2=
The following was posted on the Irish Linux User Group mailing list:
 
 
 
 
<quote>
 
 
ok, let's say your cursor is on ok, and you delete this paragraph with
 
 
the command [d}] (just the d} part, for this mail i'm wrapping
 
 
keystrokes in []'s). the reason you deleted it is because you want to
 
 
move it to another file.
 
 
 
 
so now you open the other file with [:e other.file.txt<return>]. as
 
 
you're scrolling down to where you want to put it, you accidentally
 
 
delete/yank some text.
 
 
 
 
you've saved the last file and now doing [p] just inserts the text you
 
 
just deleted/yanked. how can you get back what you deleted? vim
 
 
extends vi's numbered delete buffers so that they work from one file to
 
 
the next - switching files doesn't delete the numbered delete buffers.
 
 
 
 
the numbered buffers are numbered from 0 to 9. ["0p] is the same as
 
 
plain old [p]. ["1p] is the buffer from the previous delete, ["2p] is
 
 
from the delete before that, etc. note that while ["0p] has the last
 
 
delete or yank, the other numbered buffers only contain previous
 
 
deletes.
 
 
 
 
it's handy, and thanks to donncha for looking it up the other day while
 
 
i was on the train.
 
 
 
 
</quote>
 
 
Credit where credit due, it was Kevin Lyda who posted this.
 
 
}}
 
}}
  +
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 <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.
== Comments ==
 
type :reg
 
   
  +
Now typing <code>p</code> simply pastes the text that you just deleted or yanked.
'''Anonymous'''
 
, December 11, 2004 9:21
 
----
 
This is pretty magic as well
 
   
  +
Fortunately, Vim remembers previous deletes/yanks in the numbered registers. You can enter the command <code>:reg</code> to list all the registers.
"1p....
 
   
  +
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.
put each numeric register successively
 
   
  +
Small deletes (less than a complete line) do not fill the numbered registers.
(where the dot is the vi(m) repeat operator)
 
   
  +
==Registers==
zzapper
 
  +
*{{help|registers}}
, December 11, 2004 15:31
 
  +
*{{help|quote_number}}
----
 
Isn't it pity that this works only for yanks longer than one line ?
 
   
 
==Comments==
vlmarek--AT--volny.cz
 
 
This is pretty magic as well:
, December 12, 2004 5:03
 
  +
<pre>
----
 
 
"1p....
This is called yank-pop in emacs, it is very useful.
 
  +
</pre>
Emacs has unlimited depth for yank-pop, and it will
 
cycle thru the list when pasting.
 
   
 
put each numeric register successively (where the dot is the Vim repeat operator).
However, in Vim it is limited to 10 registers and
 
not intuitive.
 
   
 
Perci Merci.
 
, December 14, 2004 16:25
 
 
----
 
----
 
This is called yank-pop in emacs, it is very useful.
["0] does not give you the last delete, it gives you the last yank. The last delete: ["1]
 
   
 
Emacs has unlimited depth for yank-pop, and it will cycle thru the list when pasting.
I may have something set different although I don't think so.
 
   
 
However, in Vim it is limited to 10 registers and not intuitive.
sef--AT--medi_notes.com
 
, December 29, 2004 12:09
 
----
 
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).
 
   
benw--AT--plasticboy.com
 
, January 10, 2005 7:25
 
 
----
 
----
 
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). See :help redo-register for further Information
Multiple deletes get cycled through the 1-9 registers, but multiple yanks do not.
 
eg: If you want to do 3 different deletes and then paste them somewhere else, this tip works for you. If you want to do 3 different yanks and paste them somewhere else, you are out of luck. You manually have to do a "1, "2, "3 before each.
 
 
Is there a way to get yanks to cycle registers like deletes?
 
 
 
RichardBronosky
 
, May 27, 2005 11:36
 
----
 
Oh, and here is the kicker!
 
 
This really hurts me so much that I sometimes launch TextPad to avoid this behavior...
 
1. Use "v" to select some text that you want to paste in a bunch of places.
 
2. Use "y" to yank it.
 
3. Use "v" to select some text that you want to replace.
 
4. Use "p" to paste.
 
5. Use "v" to select the next chunk of text that you want to replace.
 
6. Use "p" to paste. OH BUT WAIT THAT'S NOT THE TEXT I WANTED TO PASTE! It pastes the text from step 3, not step 1.
 
 
I really wish yanks cycled the registers like deletes do. Again I ask, "Does anyone have a solution?"
 
   
RichardBronosky
 
, August 29, 2005 8:56
 
 
----
 
----
<!-- parsed by vimtips.py in 0.266046 seconds-->
 

Revision as of 07:56, 17 June 2015

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 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). See :help redo-register for further Information