Quick intro to custom Vim Mappings
One of the best things about vim is its ability to create custom mappings for almost any key in all modes.
Suppose you want Ctrl+S to save your document while you are in insert mode, because pressing
to switch to normal mode, save the file, and return back to insert mode is a bit too much. According to vim philosophy, it actually is too much, and thus you can map Ctrl+S to those keys just as easily.
For this, add the following to your vimrc
inoremap <C-S> <Esc>:w<Enter>i
The command has separate parts but follows the format
<cmd> <lhs> <rhs>
The command maps lhs to rhs in the mode specified by cmd.
<cmd> can be further broken down in the following format:
where the following modes are common (All
modes can be viewed
(none): normal, visual, operator-pending mode i: insert mode v: visual mode n: normal mode
nore is used for no-remapping, i.e. the default functions
rhs and not their aliases will be used. When skipped,
rhs will be further resolved if a remapping is found.
Vim, even has a max resolve-depth in case of an infinite loop.
rhs the keys are named as follows:
<C-a> : Ctrl + a <S-a> : Shift + a <A-a> : Alt + a <C-S-a> : Ctrl + Shift + a <Enter> <BS> : Backspace etc..
The whole list can be viewed
or using the
:help key-notation command inside vim.