How many times have you yanked a line, deleted some white space for clean up, and went to paste what you thought you yanked only to spit out what you just deleted? Shoot! (Undo. Undo. Undo.)
Well fret no more my friend! Let’s tap into Vim’s registers to help eliminate that frustration.
Registers are a powerful feature in Vim. You can record macros, use expressions and even send text to a black hole. But for today, let’s just think of registers as a big fancy clipboard where our deletes and yanks live.
To see what you’ve already got in your registers, type:
That lists your latest registers. It’s a big cheat sheet of your deletes and
yanks. The key on the left is the combination to the value on the right. So if I enter
in a key and the put command like:
"2p Vim will paste in: I’m not friends with anyone, because I’m friends with
That’s helpful for finding something I deleted a while back, but I don’t necessarily want to pop the register list everytime. Luckily there’s a bit of method to the madness and these are the registers I find myself using the most:
- The most recently yanked text:
- The most recently deleted line:
"1p(1-9 is your delete history in descending order)
- The most recently deleted text:
"-p(For deletes that aren’t a whole line)
- The most recently searched for text:
Again, there’s quite a bit you can do with registers that I haven’t touched on
or really taken advantage of myself… yet. I’ll save that for another day.
But if you feel like diving in, you can always ask Vim for the nitty gritty details with
As my Grandad always used to say:
Just cause you delete don’t mean it’s gone, pop open a register and get off my lawn!