Index

Table of contents

vim key bindings

key syms

letters
[a-zA-Z]
arrow keys
<Up>
<Down>
<Left>
<Right>
other special keys (:help key-notation)
<BS>           Backspace
<Tab>          Tab
<CR>           Enter
<Enter>        Enter
<Return>       Enter
<Esc>          Escape
<Space>        Space
<Up>           Up arrow
<Down>         Down arrow
<Left>         Left arrow
<Right>        Right arrow
<F1> - <F12>   Function keys 1 to 12
<1,>#2..#9,#0 Function keys F1 to F9, F10
<Insert>       Insert
<Del>          Delete
<Home>         Home
<End>          End
<PageUp>       Page-Up
<PageDown>     Page-Down
<bar>          the '|' character, which otherwise needs to be escaped '\|'

composite keys

composite keys example
:nnoremap ;g :echo 'First command'<CR>
:nnoremap ;k :echo 'Second command'<CR>
:nnoremap ;= :echo 'Third command'<CR>

modifiers

control modifier
<C-[key]>
shift modifier
<S-[key]>
alt modifier (avoid alt as only modifier)
<A-[key]>
control & shift modifier
<C-S-[key]>
example
:nnoremap + :bn<CR>
:nnoremap _ :bp<CR>
:nnoremap - :bd<CR>
:nnoremap <S-F> :!date<CR>
:nnoremap <S-Insert> :!date<CR>
:nnoremap <S-F12> :!date<CR>
:nnoremap <C-F> :!date<CR>
:nnoremap <C-F> :!date<CR>
:nnoremap <C-S-F> :!date<CR>
:nnoremap <C-A-F> :!date<CR>
:nnoremap <S-Up> :echo "up"<CR>
:nnoremap <S-Down> :echo "down"<CR>
:inoremap <S-Up> <Esc>:echo "up"<CR>
:inoremap <S-Down> <Esc>:echo "down"<CR>
documentation
:help key-notation
https://vimhelp.org/intro.txt.html#key-codes

remappable keys

unbound keys (any mode)
<F1-F12>
safe to remap in normal mode
\         <leader> key (:help leader)
=         auto indent
;         Repeat latest f, t, F or T (move commands) in forward direction
,         Repeat latest f, t, F or T (move commands) in backward direction
?         Reverse search, alternative forward search '/' with shift-N
Reverse search word, alternative forward search '*' with shift-N
s         substitute, alternative 'cl' or 'c<Space>'
S         substitute, just use 'cc' instead
Q         ex-mode
+         jump to start of next line (after whitespace), alternative <CR>
-         jump to previous line      (after whitespace)
_         jump to begin of line      (after whitespace)
<CR>      next line, alternative j or <down>
<space>   move forward one character
<C-H>     == same as 'h'
<C-J>     == same as 'j'
<C-K>     unused
<C-L>     == redraw screen
<C-P>     same as k or <up>
<C-N>     same as j or <down>
<C-\>     unused, use <nowait>
<C-_>     unused, maps to control-/
<BS>      go back one character (wraps)
<TAB>
remappable in insert mode
<C-B>     unused
<C-F>     unused
<C-H>     == backspace
<C-I>     == tab
<C-J>     == enter
<C-L>     only applicable if 'insertmode' option is set
<C-]>     trigger abbreviation
<C-\>     unused
<C-_>     unused, maps to control-/

<S-TAB>   unused
remappable in visual mode
m         unused
q         record macro in visual mode?
Q         unused
S         == 'R'
Z         unused
<C-D>     == pgdn
<C-F>     unused
<C-H>     == backspace
<C-I>     unused
<C-J>     == enter
<C-K>     unused
<C-L>     unused
<C-M>     == enter
<C-N>     == enter
<C-O>     unused
<C-P>     unused
<C-T>     unused
<C-U>     == pgup
<C-W>     unused
<C-]>     lookup selection as tag
<C-\>     unused
<C-_>     unused, maps to control-/

mapping keys

list key mappings (overrides)
:map  # normal, visual, select & operator pending
:map! # insert & command-line
:nmap # normal mode
:imap # insert mode
:vmap # visual & select
remove keymapping
:unmap  [key]
:unmap! [key]
:nunmap [key]
:iunmap [key]
:vunmap [key]
remove default mapping
:map q: <Nop>

creating mapping

hello world example
:map - :echo 'Current time is ' . strftime('%c')<CR>
:map <F12> :echo 'Current time is ' . strftime('%c')<CR>
escape sequence for a bar '|' in a command
:map <F8> :w <bar> !clear; ls<CR>
to reference the current file
:map <space> :echo expand("%") . strftime(' - %c')<CR>
:map <space> :echo expand("%:S:r") . strftime(' - %c')<CR>
to reference the word currently under the cursor
:map <space> :echo expand("<cword>") . strftime(' - %c')<CR>
use <silent> to have Vim not echo the command to the bottom of the screen
:nnoremap <silent> <space><space> :nohlsearch<CR>
use <expr> to call a function, rather than executing a set of keys
:inoremap <expr> . InsertDot()

key binding examples

copy and paste example (like windows)
:vmap <C-c> "+yi
:vmap <C-x> "+c
:vmap <C-v> c<ESC>"+p
:imap <C-v> <ESC>"+pa
Make shift-insert paste like in Xterm
:map <S-Insert> <MiddleMouse>
:map! <S-Insert> <MiddleMouse>
expand %% in ex command to path of current file
:cnoremap <expr> %% getcmdtype() == ':' ? expand('%:h').'/' : '%%'

references

https://learnvimscriptthehardway.stevelosh.com/chapters/06.html
https://vim.fandom.com/wiki/Unused_keys