When I want to copy a line and paste it in the current line after deleting the current line's contents, I end up pasting the same line that was deleted as the clipboard entry gets changed after pressing d
Asked
Active
Viewed 729 times
3 Answers
9
You can access the previous content of the unnamed register with registers "1
to "9
:
"3p
Register "0
always contains the last explicit yank:
"0p
And you can yank to a named register "a
to "z
. If you want to save a snippet for later, using named registers is a very good idea:
"ey
"ep
See :help registers
.

Lieven Keersmaekers
- 57,207
- 13
- 112
- 146

romainl
- 186,200
- 21
- 280
- 313
-
So where does the second last yank gets stored? Seems it is not stored in 1 for me? – spharish May 26 '16 at 13:58
-
Woo, yanking to named registers is exactly what I was after but seldom mentioned in posts about yank registers. `"py` and `"pp` are my new favourite (n)vim commands :) – htaccess Sep 19 '22 at 21:53
3
In addition to the information given about registers already, you can type
:reg
to get a list of what is currently stored in all of the registers.
You can then use the 2-character code that is displayed on the left (beginning with a "
eg. "2
) followed by p
while in normal mode to paste the contents of that register.

Shinkawa91
- 127
- 1
- 8
-
Is there a way to know the register contents without typing :reg, like most recent in 0, second most recent in 1, etc. Because I often need the second most recent value? – spharish May 27 '16 at 03:54
-
I'm unsure about yanks, but deleted content will be stored in successive registers. So `"0` will always contain the last yank (unless another register was specified). `"1` will contain the contents of the last delete or change command. If you make another delete after this, the contents of register `"1` move to `"2`, and the recently deleted content moves to `"1`. – Shinkawa91 May 27 '16 at 11:13
2
To replace the current line with whatever is in the clipboard, you can select that line and paste. ie do a
Shiftvp

sudo bangbang
- 27,127
- 11
- 75
- 77