Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the meaning of 'inoremap' in vimrc

Tags:

vim

There is a line below in vimrc example file

inoremap Ctrl-u Ctrl-G u Ctrl-u 

What's the meaning of inoremap and what's the function of this line?

like image 885
Aaron Avatar asked Feb 10 '12 02:02

Aaron


People also ask

What is Inoremap?

To remove a keymap from insert mode, use the ':iunmap' command. For example, the following command removes the insert mode map for . :iunmap <F2> As printable keys insert a character in the current buffer in insert mode, you should use non-printable keys to create insert mode maps.

What is silent in Vimrc?

<silent> tells vim to show no message when this key sequence is used. <leader> means the key sequence starts with the character assigned to variable mapleader -- a backslash, if no let mapleader = statement has executed yet at the point nmap executes.

How do I map a key in Vimrc?

To map a sequence of keys to execute another sequence of keys, use the ':map' command. For example, the following command maps the <F2> key to display the current date and time. The ':map' command creates a key map that works in normal, visual, select and operator pending modes.

What is cr in vim?

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


2 Answers

For more on why the command has such a bizarre name see this excellent description between the difference between map and noremap. Really good to know!

To summarise that article, here's a choice quote:

One downside of the *map commands is the danger of recursing...

Vim offers another set of mapping commands that will not take mappings into account when they perform their actions.

So noremap came about to avoid horrible recursion of mappings like

:nmap dd O<esc>jddk 

where the dd in the right-hand side of the map recurses back to the left-hand side definition of the map, and Vim gets stuck in an infinite loop!

like image 76
LondonRob Avatar answered Oct 09 '22 18:10

LondonRob


The vim :help inoremap is very poetic about this:

:ino[remap] {lhs} {rhs}         mapmode-i             :ino :inoremap :ln[oremap] {lhs} {rhs}         mapmode-l             :ln  :lnoremap :cno[remap] {lhs} {rhs}         mapmode-c             :cno :cnoremap                     Map the key sequence {lhs} to {rhs} for the modes                     where the map command applies.  Disallow mapping of                     {rhs}, to avoid nested and recursive mappings.  Often                     used to redefine a command.  {not in Vi} 

Thus it makes some insert-mode mappings for ^U that show the filename (^G, undo the most recent change (u), and scrolls the buffer upwards by half a screen (^U).

I have no idea why someone would want this specific sequence of commands, except to demonstrate the inoremap feature -- the ^U at the refers to the meaning the command had when the definition was created, rather than calling back into the redefined ^U mapping.

like image 38
sarnold Avatar answered Oct 09 '22 18:10

sarnold