What does <c-r>= means in Vim

Vim

Vim 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 onto something different breaks it.

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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionlithuakView Question on Stackoverflow
Solution 1 - VimromainlView Answer on Stackoverflow
Solution 2 - VimIainView Answer on Stackoverflow