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?
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.
<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.
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.
The <CR> in vim mappings is the carriage return usually the Enter on your keyboard.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With