Alex R. Young
May 19, 2012 · 1 min read

Last week I wrote about Vim’s registers, and this week you’ll see one of the many reasons why they’re essential, in the form of CTRL-R.

Inserting Registers in Insert Mode

When writing in insert mode, it’s possible to paste a register at the current location without leaving insert mode. To do this, press CTRL-R then type the name of a register. For example, CTRL-R a will insert the contents of a.

The text is inserted as if it were typed: that means autoindent will be respected. Pressing CTRL-R twice will insert the text literally.

Expression Register

Typing CTRL-R = allows an expression to be entered -- press return to insert the result. This could be any expression, but an easy to learn trick is to use it for simple mathematics.

Let’s say I wanted to insert the number of milliseconds in a day. Rather than leaving Vim and using a calculator or REPL, I could type CTRL-R =1000 * 60 * 60 * 24 and "86400000" will be inserted at the current position.

Command Mode

Typing CTRL-R in command mode (not normal mode) will also insert the contents of a register.

Further Reading

For more on using CTRL-R in insert mode, see :help i_CTRL-R. The command mode equivalent is also documented in :help c_CTRL-R.

usevim

A blog about Vim

Alex R. Young

Written by

Software critic.

usevim

usevim

A blog about Vim

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade