Last Updated: February 25, 2016
·
744
· underhilllabs

Vim: Paste buried yanked text from Register

This is a quick tip. I was just editing a file and I visually selected and deleted a big chunk of code, that I was going to paste into its own function. But I accidentally deleted another minor line before I could paste the main chunk of code.

In the past I would have hit u a bunch of times to get back to where I had selected the original text and I would have grumpily started again. However a light bulb lit up over my keyboard! The yanked text is still in a register!

Check the Registers with :reg

So, I checked the registers ... and there it was in register "1

:reg
--- Registers ---
""   Helper function to
"0   /**^J * Helper function to save ...
"1     $dcs_id = db_insert('interesting ...

Paste from a Register

So, I jumped to the correct spot in the new function and pasted from the register with: "1p

tldr;

  • Print out registers
:reg
  • Paste the register
"1p

To paste from a register, type the register name, in this case "1 and then the paste command p or P.