vim cut and paste history

The

:help registers

command reveals that there are 10 numbered registers ("0 to "9).

Register "0 is the most recent thing yanked; register "1 has the most recent deleted text, register "2 the previous deletion, "3 has the deletion before that, and so on.

If you delete each line in turn, registers "1, "2, "3 and "4 will contain "Vim", "And", "World" & "Hello", respectively.

You can verify this by using the :reg (or :registers) command:

:reg
""   Vim^J
"1   Vim^J
"2   And^J
"3   World^J
"4   Hello^J

So after deleting the four lines one at a time, you could recover the 2nd line ("World") with

"3p

because it's the third most recent deletion.


In addition to njd's answer, this can be simplified with the YankRing plugin. As well as making it easier to browse the previous yanks, you can configure some keys to allow you to pop previous yanks off the 'stack'. This allows you to do:

yy    " Copy first line
yy    " Copy second line
yy    " Copy third line
yy    " Copy fourth line
" Assumes you've mapped ,p to be the pop command: choose your preferred key or key-combination
,p    " Paste fourth line and pop it off the Yank Ring
,p    " Paste third line and pop it off the Yank Ring
,p    " Paste second line and pop it off the Yank Ring
,p    " Paste first line and pop it off the Yank Ring

Tags:

Vim