Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does <c-r>= means in Vim

Tags:

vim

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?...

like image 252
lithuak Avatar asked Jun 02 '12 12:06

lithuak


People also ask

What does CR in vim mean?

The <CR> in vim mappings is the carriage return usually the Enter on your keyboard.

What does CR mean command?

The CR command collects failure information and either displays it on the console or dumps the information to a floppy disk.

What key is CR?

Short for carriage return, CR is often used to represent a carriage return done by pressing the Enter and Return key.


1 Answers

<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

like image 137
romainl Avatar answered Oct 01 '22 00:10

romainl