Tip 524 Printable Monobook Previous Next

created August 3, 2003 · complexity basic · author Yakov Lerner · version 6.0

The <CTRL-R>= things evaluates the expression. For example:


<CTRL-R>= works in insert mode and in command mode. I felt it more convenient if <CTRL-R>= did the same thing in normal mode too.

I have this in my vimrc:

map <CTRL-R>= :echo

Now <CTRL-R>=123*456<CR> evaluates expressions for me in all 3 modes: normal mode, insert mode, and command mode. In fact I found it much more convenient to do casual calculations using <CTRl-R>= in normal mode than in any other mode.

Be warned: when typing <CTRL-R>= in normal mode, don't make long pause before '='. <CTRL-R> alone means 'redo' in normal mode. Vim is very smart, and figures the difference between single <CTRL-R> (which is 'redo') and the mapped sequence <CTRL-R>= (which is remapped). The 'timeoutlen' option controls this difference. The default value of 'timeoutlen' option is very convenient.

This is an expansion of Using Vim as calculator.

References[edit | edit source]

Comments[edit | edit source]

To get the behavior like i_CTRL-r in normal mode, use @=. For example, in normal mode, @='dd'<CR> will delete the current line just as if you had pressed dd in normal mode.

For more information. You can also do things like

:let @a = 'dd'

and then press @a in normal mode. This does the same thing.

Community content is available under CC-BY-SA unless otherwise noted.