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?
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!
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.
I also wondered about this. See http://vim.wikia.com/wiki/Mapping_keys_in_Vim_-Tutorial(Part_1)#Insert_mode_maps :
To map keys that work only in the insert and replace modes, use the 'imap' or 'inoremap' command.
Example: The following command maps to insert the directory name of the current buffer:
:inoremap <F2> <C-R>=expand('%:p:h')<CR>
To display the currently defined insert mode maps, use the 'imap' command without any argument:
:imap
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. Some examples for non-printable keys include the function keys , keys prefixed with the Ctrl or Alt key.
[snip]
So, for example, in my ~/.vimrc I have
inoremap jk <ESC>
inoremap jj <Esc>
which when pressed in Insert mode return me to Normal mode.