Vim cheat sheet

May 16, 2014


  • za to toggle current fold
  • zm to close, zr to open


from windows

A buffer is the in-memory text of a file.
A window is a viewport on a buffer.
A tab page is a collection of windows.

  • Opening: CTRL-W and v(vert), s(split/duplicate), n(horiz)
  • Closing: CTRL-W and q(quit), c(close)
  • Moving cursor: CTRL-W and up, down, left, right
  • Moving windows: CTRL-W CTRL-O make window the only(maximize)

Plugin mappings

  • sensible: CTRL-u in insert mode: delete backwards, for real
  • sneak: s or S and then two letters for faster jumping, ; to repeat
  • table-mode: <leader>tm to toggle, <leader>tr to realign, SHIFT-jklö to jump table cells
  • multiple cursors: CTRL-n to select word, CTRL-p for undo, CTRL-x to skip the current one

Settings in vimrc

" vimrc
" Remember last position
if has("autocmd")
  au BufReadPost * if line("'\"") > 1 && line("'\"")
  \ <= line("$") | exe "normal! g'\"" | endif
" set pyton3
let g:python3_host_prog = '/usr/bin/python3'
" highlighting
hi Search cterm=black ctermfg=white ctermbg=red
" German keyboard layout
nnoremap j h
nnoremap k j
nnoremap l k
nnoremap ö l


see scroll

  • scroll line for line: CTRL-e(up) CTRL-y(down)
  • scroll window half a screen: CTRL-u(up) CTRL-d(down)
  • scroll full windows: SHIFT-UP and SHITFT-DOWN
  • move line to top of window: z-ENTER
  • Jump back CTRL-o (and CTRL-i for forward)
  • Move to last position '' or use double backticks
  • delete(in insert move): like in fish:
    CTRL-k to end, CTRL-u to start, CTRL-w to delete word
  • CTRL-h for backspace, CTRL-j for enter
  • run single command in insert mode: CTRL-O
  • deleting(normal)(swap a for i for inner):
    swap c for d: deletng, for v: visual select, for y: ‘copy’
    • ciw: change in word
    • cis: change in sentence
    • cib and diB: change () and {} blocks
    • cip: change in paragraph
    • cit: change in tags(html)
  • D to delete from cursor to end of line
  • move by whole words(no whitespace): W
  • (), {}: jump sentences, paragraphs
  • H M L: move to top, middle, bottom of viewport
  • marks: m(register): mark point (here: x)
    • 'x(single quote): jump to point(my mapping, default is backtick)
  • pasting: p after cursor, P before cursor
  • CTRL-r-x to insert from register x while in insert mode

Very useful

  • wrap lines visual select and then gq
  • use previous selection gv for selecting previous visual selection gi to go into insert mode in previous position
  • o in visual mode jumps to other end of selection
  • = to reformat text
  • ciw''P: enclose in quotes


  • get out of “completion mode” / resume flow control CTRL-q
  • save and quit vim ZZ, to only quit: ZQ, to write all files and quit: :xa
  • escape CTRL-c
  • indents use CTRL-i(indent) and CTRL-d(remove indent) in insert move,
    use > and < in visual mode(once) and in normal(press twice)
  • jump to line [line nr], G
  • recording
    q [letter] to start recording
    q to stop, @ [letter] to play back
  • parenthesis ([{ jumping %
  • manipulate multiple lines use visual selection and then :norm <command>, e.g. :'<,'>norm A,
    or block(CTRL-v) select and then $A<text> to append to all lines
  • numbers CTRL-a and CTRL-x increment and decrement
  • netrw use CTRL-o and CTRL-i to switch, use % to create a file
  • replacing/‘substituting’
    set incsearch and then search /oldstring, replace with %s//newstring/
    :s/oldstring/newstring (only once)
    :s/oldstring/newstring/gic: global, ignore case and confirm each :[startline],[endline]s/oldstring/newstring/g replace only between specified lines
    &: **repeat last subsitution
  • writing
    visual selection only writes the selected part
    wr :r loads file, can be combined with !<command>
  • windows CTRL-W CTRL-W switch windows
  • neat
    • CTRL-X [o p n] auto-complete and more
    • ~ toggle upper/lowercase, in visual mode: u and U for lower/uppercasing
    • :bro ol browse oldfiles
  • dictionary
    use zg on a word to add it to dictionary
    located in ~/<vimdir>/spell/en.utf-8.add
  • fix encoding
    :set bomb
    :set fileencoding(s)=utf-8
  • whitespace
    %le for removing indents
    g/^$/d for removing blank lines
    :%s/\s\+$// for removing trailing whitespace
  • centering :ce columns: center with columns width
  • abbreviations
  • ab lw Long word: expand ’lw’ to “Long word” una lw: unset the abbreviation
  • tabs to spaces


:nmap - Display normal mode maps
:imap - Display insert mode maps
:vmap - Display visual and select mode maps
:smap - Display select mode maps
:xmap - Display visual mode maps
:cmap - Display command-line mode maps
:omap - Display operator pending mode maps


  • Use registers more often
  • Use ci{ and the like more often
  • Jump by s and f instead of hjkl
  • Use CTRL-h and CTRL-j for backspace and enter
  • map NOP to unused extension mappings for uncluttering :map and no surprises
  • Explain d/D, y/Y, c/C, p/P, b/B, i/I, … in various modes