Vim Tips Wiki
(Move categories to tip template)
(Remove html character entities)
 
Line 12: Line 12:
 
|category2=
 
|category2=
 
}}
 
}}
The <CTRL-R>= things evaluates the expression. For example:
+
The <CTRL-R>= things evaluates the expression. For example:
  +
<pre>
&lt;CTRL-R&gt;=12+34&lt;cr&gt;
 
  +
<CTRL-R>=12+34<CR>
  +
</pre>
   
&lt;CTRL-R&gt;= works in insert mode and in command mode. I felt it more convenient if &lt;CTRL-R&gt;= did the same thing in normal mode too.
+
<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:
+
I have this in my [[vimrc]]:
  +
<pre>
map &lt;CTRL-R&gt;= :echo
+
map <CTRL-R>= :echo
  +
</pre>
   
Now &lt;CTRL-R&gt;=123*456&lt;CR&gt; 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 &lt;CTRl-R&gt;= in normal mode than in any other mode.
+
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 &lt;CTRL-R&gt;= in normal mode, don't make long pause before '='. &lt;CTRL-R&gt; alone means 'redo' in normal mode. Vim is very smart, and figures the difference between single &lt;CTRL-R&gt; (which is 'redo') and the mapped sequence &lt;CTRL-R&gt;= (which is remapped). The 'timeoutlen' option controls this difference. The default value of 'timeoutlen' option is very convenient.
+
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 [[VimTip73|Using Vim as calculator]].
 
This is an expansion of [[VimTip73|Using Vim as calculator]].
Line 33: Line 37:
   
 
==Comments==
 
==Comments==
To get the behavior like i_CTRL-r in normal mode, use @=. For example, in normal mode, @='dd'&lt;cr&gt; will delete the current line just as if you had pressed dd in normal mode.
+
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.
 
*{{help|@}}
 
*{{help|@}}
   

Latest revision as of 08:52, 29 September 2008

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>=12+34<CR>

<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[]

Comments[]

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.