Vim Cheat Sheet
Column 1 insert before the cursor in small i insert at the beginning of the line in capital I insert (append) after the cursor in small a insert (append) at the end of the line in capital A append (open) a new line below the current line o append (open) a new line above the current line in capital O insert (append) at the end of the word ea delete the character before the cursor during insert mode Ctrl +h delete word before the cursor during insert mode Ctrl +w add a line break at the cursor position during insert mode Ctrl +j indent (move right) line one shiftwidth during insert mode Ctrl +t de-indent (move left) line one shiftwidth during insert mode Ctrl +d insert (auto-complete) next match before the cursor during insert mode Ctrl +n insert (auto-complete) previous match before the cursor during insert mode Ctrl +p insert the contents of register x Ctrl +rx Temporarily enter normal mode to issue one normal-mode command x. Ctrl +ox exit insert mode Esc or Ctrl +c start visual mode, mark lines, then do a command (like y-yank) v start linewise visual mode in capital V move to other end of marked area o start visual block mode Ctrl +v move to other corner of block O mark a word aw a block with () ab a block with {} aB a block with <> tags at inner block with () ib inner block with {} in capital iB inner block with <> tags it exit visual mode Esc or Ctrl +c shift text right > shift text left < yank (copy) marked text y delete marked text d switch case ~ change marked text to lowercase u change marked text to uppercase in capital U
:reg[isters] yank into register x "xy paste contents of register x "xp yank into the system clipboard register "+y paste from the system clipboard register "+p Open help for keyword :h[elp] keyword close current pane :clo[se] Save file as :sav[eas] file open a terminal window :ter[minal] open man page for word under the cursor K last yank unnamed register, last delete or yank current file name alternate file name clipboard contents (X11 primary) clipboard contents (X11 clipboard) last search pattern last command-line last inserted text last small (less than a line) delete expression register black hole register 0
"
%
#
*
+
:
.
-
=
_ list of marks :marks set current position for mark A ma jump to position of mark A `a yank text to position of mark A y`a go to the position where Vim was previously exited `0 go to the position when last editing this file `" go to the position of the last change in this file `. go to the position before the last jump `` list of jumps :ju[mps] go to newer position in jump list Ctrl +i go to older position in jump list Ctrl +o list of changes :changes go to newer position in change list g, go to older position in change list g; jump to the tag under cursor Ctrl +] record macro a qa stop recording macro q run macro a @a rerun last run macro @@ Column 2 edit a file in a new buffer :e[dit] file go to the next buffer :bn[ext] go to the previous buffer :bp[revious] delete a buffer (close a file) :bd[elete] go to a buffer by index # :b[uffer]# go to a buffer by file :b[uffer] file list all open buffers :ls or :buffers open a file in a new buffer and split window :sp[lit] file open a file in a new buffer and vertically split window :vs[plit] file edit all buffers as vertical windows :vert[ical] ba[ll] edit all buffers as tabs :tab ba[ll] split window Ctrl +ws split window vertically Ctrl +wv switch windows Ctrl +ww quit a window Ctrl +wq exchange current window with next one Ctrl +wx make all windows equal height & width Ctrl +w= move cursor to the left window (vertical split) Ctrl +wh move cursor to the right window (vertical split) Ctrl +wl move cursor to the window below (horizontal split) Ctrl +wj move cursor to the window above (horizontal split) Ctrl +wk make current window full height at far left (leftmost vertical window) Ctrl +wH make current window full height at far right (rightmost vertical window) Ctrl +wL make current window full width at the very bottom (bottommost horizontal window) Ctrl +wJ make current window full width at the very top (topmost horizontal window) Ctrl +wK manually define a fold up to motion zf delete fold under the cursor zd toggle fold under the cursor za open fold under the cursor zo close fold under the cursor zc reduce (open) all folds by one level zr fold more (close) all folds by one level zm toggle folding functionality zi jump to start of next change ]c jump to start of previous change [c obtain (get) difference (from other buffer) do or :diffg[et] put difference (to other buffer) dp or :diffpu[t] make current window part of diff :diffthis update differences :dif[fupdate] switch off diff mode for current window :diffo[ff] Tip To view the differences of files, one can directly start Vim in diff mode by running vimdiff in a terminal. One can even set this as git difftool. vimdiff
git difftool. move cursor down j move cursor up k move cursor right l
move cursor down (multi-line text) gj move cursor up (multi-line text) gk move to top of screen h move to middle of screen m
move to bottom of screen L jump forwards to the start of a word w jump forwards to the start of a word (words can contain punctuation W jump forwards to the end of a word e jump forwards to the end of a word (words can contain punctuation) e jump backwards to the start of a word b jump backwards to the start of a word (words can contain punctuation) b jump backwards to the end of a word ge
jump backwards to the end of a word (words can contain punctuation) ge move cursor to matching character (default supported pairs: '()', '{}', '[]' - use :h matchpairs in vim for more info) % jump to the start of the line 0 jump to the first non-blank character of the line ^ jump to the end of the line $ jump to the last non-blank character of the line g_ go to the first line of the document gg go to the last line of the document G go to line 5 5gg 5G move to local declaration gd move to global declaration gD jump to next occurrence of character fx jump to before next occurrence of character x tx jump to the previous occurrence of character x Fx jump to after previous occurrence of character x Tx repeat previous f, t, F or T movement ; repeat previous f, t, F or T movement, backwards , jump to next paragraph (or function/block, when editing code) } jump to previous paragraph (or function/block, when editing code) { center cursor on screen zz position cursor on top of the screen zt position cursor on bottom of the screen zb move screen down one line (without moving cursor) Ctrl +e move screen up one line (without moving cursor) Ctrl +y move screen up one page (cursor to last line) Ctrl +b move screen down one page (cursor to first line) Ctrl +f move cursor and screen down 1/2 page Ctrl +d move cursor and screen up 1/2 page Ctrl +u Column 3 search for pattern in multiple files :vim[grep] pattern {`{file}`} e.g. : vim[grep] foo *** jump to the next match :cn[ext] jump to the previous match :cp[revious] open a window containing the list of matches :cope[n] close the quickfix window :ccl[ose] open a file in a new tab :tabnew or :tabnew {page.words.file} move the current split window into its own tab Ctrl +wT move to the next tab gt or :tabn[ext] move to the previous tab gT or :tabp[revious] move to tab number # #gt move current tab to the #th position (indexed from 0) :tabm[ove] # close the current tab and all its windows :tabc[lose] close all tabs except for the current one :tabo[nly] command - run the command on all tabs (e.g. :tabdo q - closes all opened tabs) :tabdo search for pattern pattern search backward for pattern ?pattern 'very magic' pattern: non-alphanumeric characters are interpreted as special regex symbols (no escaping needed) \vpattern repeat search in same direction n repeat search in opposite direction (in capital) N replace all old with new throughout file :%soldnewg - replace all old with new throughout file with confirmations :%soldnewgc remove highlighting of search matches :noh[lsearch] write (save) the file, but don't exit :w write out the current file using sudo :w !sudo tee % write (save) and quit :wq or :x or ZZ quit (fails if there are unsaved changes) :q quit and throw away unsaved changes :q! or ZQ write (save) and quit on all tabs :wqa indent (move right) line one shiftwidth >> de-indent (move left) line one shiftwidth << indent a block with () or {} (cursor on brace) >% indent inner block with () >ib indent a block with <> tags >at re-indent 3 lines 3== re-indent a block with () or {} (cursor on brace) =% re-indent inner block with {} =iB re-indent entire buffer gg=G paste and adjust indent to current line ]p move cursor left h replace a single character in small . r replace more than one character, until ESC is pressed. R join line below to the current one with one space in between J join line below to the current one without space in between gJ switch case up to motion g~ change to lowercase up to motion gu change to uppercase up to motion gU change (replace) entire line cc change (replace) to the end of the line c$ or C change (replace) entire word ciw change (replace) to the end of the cw or ce delete character and substitute text press in small s delete line and substitute text (same as cc) in capital S transpose two letters (delete and paste) xp undo u restore (undo) last changed line in capital U redo Ctrl +r repeat last command .
:.,$d
:.,1d
:10,$d delete all lines containing pattern :g{pattern}d delete all lines not containing pattern :g!{pattern}d delete (cut) to the end of the line d$ or D delete (cut) character x yank (copy) a line yy yank (copy) 2 lines 2yy yank (copy) the characters of the word from the cursor position to the start of the next word yw yank (copy) word under the cursor yiw yank (copy) word under the cursor and the space after or before it yaw yank (copy) to end of line y$ or Y put (paste) the clipboard after cursor p put (paste) the clipboard after cursor and leave cursor after the new text gp put (paste) before cursor and leave cursor after the new text gP delete (cut) a line dd delete (cut) 2 lines 2dd delete (cut) the characters of the word from the cursor position to the start of the next word dw delete (cut) word under the cursor diw delete (cut) word under the cursor and the space after or before it daw delete lines starting from 3 to 5 :3,5d |