Rory's Blog
Home
Blog
Projects
Facebook
Google+
Github
RSS

Using Vim Registers

03/14/15

So, I've finally started adding new vim tricks into my habitual process. A recent addition has been using vim registers. Registers are like individual clipboards you can copy to and paste from. Using a specific register will keep its contents until that specific register is copied to again.

This is really useful, as most anything that deletes content in vim puts it in the default paste register, which makes paste-replacing lots of different content with one specific bit of content a bit difficult.

But now all I need to do is:

"<key>y

To yank content into a key register of my choice and then to past it all I have to do is:

"<key>p

And, thanks to how vim saves session-state between sessions, I still have those registers saved when I next open vim. I find it quite useful, considering I write still write these blog posts in pure HTML. Now, I have registers for creating a new paragraph, unordered list, ordered list, etc. And I can make them as complicated as I want and it won't increase the complexities of writing.

There's definitely a better way to do this, though, and I may find my current use of registers to be a misuse of a perfectly useful tool. Why do I think there's a better way to do this? Because spacing isn't automatically adjusted based on context, and I think if I were to make, say, macros (the next thing I should learn proper) to insert these tags automatically, it would both save me a keystroke and probably take advantage of spacing context.

Still, I've added registers to my vim knowledge, and whenever I may find it useful I can reach for it without the resistance of ignorance or inexperience.