The Very Basics of Vim Registers

But Why?

Registers open up a world of possibilities in Vim. If you’re not using them, then you’re potentially limiting your Vim productivity.

For example, how many times has the following situation happened to you?

You want to copy a line of text so you:

  1. Yank the line in question

  2. Delete another line along the way

  3. Attempt to put the original line, accidentally putting the deleted line

This was a major hurdle while switching from RubyMine to Vim full time. Luckily I had a much more experienced, handsome coworker (shoutouts to Tony) who revealed to me the awesome that are Vim registers.

To see them in action yourself, open Vim and type :reg

No, seriously, do it. I’ll wait.

Want to put the last line you yanked and NOT the last one you deleted? Use the 0th register. "0p

Cool right? Now, let’s go over another example.

Named Registers

Another fantastically useful feature of registers are named registers. This gives you the ability to store text under an alias for later use.

In this example I copy the final line to the ‘a’ register with: "ayy and you then you can see it in the ‘a’ register! This text can later be put with: `“ap'

Final Thoughts

We’ve only scratched the surface on what’s possible with Vim registers. Use Vim and Vim Casts both have excellent tutorials for more information.