What does <c-r>= means in Vim
VimVim Problem Overview
I came across a number of this syntax usages which I don't understand:
The first is in :help mapping:
:map <F2> a<C-R>=strftime("%c")<CR><Esc>
This sequence really does insert the value of strftime into buffer though I don't understand how. Changing
Another one is at wiki page which describes how to make omnicompletion popup menu work well:
inoremap <silent> <Esc> <C-r>=pumvisible() ? "\<C-y>" : "\<Esc>"<CR>
The same thing here.
Can anybody explain how this "<C-r>=
" thing works?...
Vim Solutions
Solution 1 - Vim
<C-r>=
, or Ctrl+R= is used to insert the result of an expression at the cursor.
I use it a lot when editing CSS to insert values:
width: <C-r>=147-33<CR>px;
width: 114px;
EDIT
<C-r>
, without =
, allows you to insert the content of any register at the cursor while staying in insert mode: <C-r>+
, for example, inserts the content of my system clipboard. see :help i_ctrl_r
.
=
is the "expression register". See :help "=
.
ENDEDIT
Solution 2 - Vim
<C-r>
is like doing CTRL+R on the keyboard. <CR>
is like hitting enter. You can find the full list by doing :help key-notation
.