You are on page 1of 2

VIM Quick Reference Card Insert mode Undoing & repeating commands

ˆVc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . insert char c literally u U . . . . . . undo last command, restore last changed line
ˆVn. . . . . . . . . . . . . . . . . . .insert decimal value of character . ˆR. . . . . . . . . . . . . . . .repeat last changes, redo last undo
Basic movement
ˆA . . . . . . . . . . . . . . . . . . . . . . insert previously inserted text n. . . . . . . repeat last changes with count replaced by n
h l k j . . . . . . . . . . . . character left, right, line up, down
b w . . . . . . . . . . . . . . . . . . . . . . . . . . . . . word/token left, right ˆ@. . . . . . .same as ˆA and stop insert → command mode qc qC . . . .record, append typed characters in register c
ge e . . . . . . . . . . . . . . . . . . . . . end of word/token left, right ˆRx . . . . . . . . . . . . . . . . . . . . . . . . insert content of register x q . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . stop recording
{ } . . . . . . . . . . . . . beginning of previous, next paragraph ˆN ˆP . . . . . . . . . . . . . . text completion before, after cursor @c . . . . . . . . . . . . . . . . . . . . execute the content of register c
( ) . . . . . . . . . . . . . . . beginning of previous, next sentence ˆW . . . . . . . . . . . . . . . . . . . . . . . . . . . delete word before cursor @@ . . . . . . . . . . . . . . . . . . . . . . . . repeat previous @ command
0 gm . . . . . . . . . . . . . . . . . . . . . . . . . beginning, middle of line ˆU . . . . . . . . . . delete all inserted character in current line :@c←-. . . . . . . . . . . .execute register c as an Ex command
^ $ . . . . . . . . . . . . . . . . . . . . . . . . . first, last character of line ˆD . . . . . . . . . . . . . . . . . . . . . . . . . . . . shift left one shift width :rg/p/c←- . . . . . . . . . . execute Ex command c on range r
nG ngg . . . . . . . . . . . . . . . . . . . line n, default the last, first ˆK c1 c2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . enter digraph b where pattern p matches
n% . . . . . . . . percentage n of the file (n must be provided) hesci . . . . . . . . . . . . . . abandon edition → command mode
n| . . . . . . . . . . . . . . . . . . . . . . . . . . . . column n of current line Complex movement
%. . . . .match of next brace, bracket, comment, #define - + . . . . . . . . . line up/down on first non-blank character
nH nL . . . . . . . . . . . . line n from start, bottom of window Copying B W . . . . . . . . . . . . . . . . . . . space-separated word left, right
M . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . middle line of window "x . . . . . . . . . . . . use register x for next delete, yank, put gE E . . . . . . . . . . . end of space-separated word left, right
:reg←- . . . . . . . . . . . . . . . show the content of all registers n . . . . . . . . down n − 1 line on first non-blank character
Insertion & replace → insert mode :reg x←- . . . . . . . . . . . . . . show the content of registers x g0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . beginning of screen line
i a . . . . . . . . . . . . . . . . . . . . . . . . . insert before, after cursor ym . . . . . . . . . . . yank the text of movement command m g^ g$ . . . . . . . . . . . . . . . . first, last character of screen line
I A . . . . . . . . . . . . . . . . . . . . insert at beginning, end of line yy or Y . . . . . . . . . . . . . . . . . . . yank current line into register gk gj . . . . . . . . . . . . . . . . . . . . . . . . . . . . screen line up, down
gI . . . . . . . . . . . . . . . . . . . . . . . . . . insert text in first column p P . . . . . . . . . . . put register after, before cursor position fc Fc . . . . . . . . . . next, previous occurence of character c
o O . . . . . . open a new line below, above the current line ]p [p . . . . . . . . . . . . . . . . . . . like p, P with indent adjusted tc Tc . . . . . . . . . . . . . before next, previous occurence of c
rc . . . . . . . . . . . . . . . replace character under cursor with c gp gP . . . . . . . . . . . like p, P leaving cursor after new text ; , . . . . . . . . . . . . . repeat last fFtT, in opposite direction
grc . . . . . . . . . . . . . . . . like r, but without affecting layout [[ ]] . . . . . . . . . . . . . . start of section backward, forward
R . . . . . . . . . . . . . replace characters starting at the cursor [] ][ . . . . . . . . . . . . . . . end of section backward, forward
gR . . . . . . . . . . . . . . . . . like R, but without affecting layout Advanced insertion
[( ]) . . . . . . . . . . . . . . . . . unclosed (, ) backward, forward
cm . . . . . . . . . . . . . change text of movement command m g?m . . . . . . . . . . perform rot13 encoding on movement m [{ [} . . . . . . . . . . . . . . . . unclosed {, } backward, forward
cc or S . . . . . . . . . . . . . . . . . . . . . . . . . . . . . change current line nˆA nˆX . . . . . . . . . . . . . . +n, −n to number under cursor [m ]m . . . . start, end of backward, forward java method
C . . . . . . . . . . . . . . . . . . . . . . . . . . . . change to the end of line gqm . . . . . . . format lines of movement m to fixed width [# ]# . unclosed #if, #else, #endif backward, forward
s . . . . . . . . . . . . . . . . . . . . . change one character and insert :rce w←- . . . . . . . . . . . center lines in range r to width w [* ]* . . . . . . . . . . start, end of /* */ backward, forward
~ . . . . . . . . . . . . . . . . . . . . . . switch case and advance cursor :rle i←- . . . . . . . left align lines in range r with indent i
g~m . . . . . . . . . . . . switch case of movement command m :rri w←- . . . . . . right align lines in range r to width w
gum gUm . . . lowercase, uppercase text of movement m !mc←- . filter lines of movement m through command c Search & substitution
<m >m . . . . . . . . . . shift left, right text of movement m /s←- ?s←- . . . . . . . . . . . . . search forward, backward for s
n!!c←- . . . . . . . . . . . . . . filter n lines through command c
n<< n>> . . . . . . . . . . . . . . . . . . . . . . . shift n lines left, right /s/o←- ?s?o←- . . . . . search fwd, bwd for s with offset o
:r!c←- . . . . . . . . . filter range r lines through command c
n or /←- . . . . . . . . . . . . . . . . . . . . . repeat forward last search
Deletion N or ?←- . . . . . . . . . . . . . . . . . . . repeat backward last search
x X . . . . . . . . . . . . . . delete character under, before cursor Visual mode # * . . . search backward, forward for word under cursor
dm . . . . . . . . . . . . . . delete text of movement command m v V ˆV . . start/stop highlighting characters, lines, block g# g* . . . . . . . . . . . . . same, but also find partial matches
dd D . . . . . . . . . . . . . delete current line, to the end of line o . . . exchange cursor position with start of highlighting gd gD . . . local, global definition of symbol under cursor
J gJ . . . . . . . . join current line with next, without space gv . . . . . . . . . . . start highlighting on previous visual area :rs/f /t/x←- . . . . . . . . . . . . . . substitute f by t in range r
:rd←- . . . . . . . . . . . . . . . . . . . . . . . . . . . . . delete range r lines aw as ap . . . . . . . select a word, a sentence, a paragraph b x : g—all occurrences, c—confirm changes
:rdx←- . . . . . . . . . . . . . delete range r lines into register x ab aB . . . . . . . . . . . . . . . . . . . select a block ( ), a block { } :rs x←- . . . . . . . . . . . repeat substitution with new r & x
Special characters in search patterns Tags Ex ranges
. ˆ . . . . . . . . . . . . . . . . . . any single character, start of line :ta t←- . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . jump to tag t , ; . . . . . . separates two lines numbers, set to first line
\< \> . . . . . . . . . . . . . . . . . . . . . . . . . . . . . start, end of word :nta←- . . . . . . . . . . . . . . . . . . jump to nth newer tag in list n . . . . . . . . . . . . . . . . . . . . . . . . . . . an absolute line number n
[c1 ..c2 ] . . . . . . . . . . . . . . a single character in range c1 ..c2 ˆ] ˆT . . . jump to the tag under cursor, return from tag . $ . . . . . . . . . . . . . . . . the current line, the last line in file
[ˆc1 ..c2 ] . . . . . . . . . . . . . . . a single character not in range :ts t←- . . . . list matching tags and select one for jump % * . . . . . . . . . . . . . . . . . . . . . . . . . . . . . entire file, visual area
\i \I . . . . . . . . . . . . . . . . . . . an identifier, excluding digits :tj t←- . . jump to tag or select one if multiple matches ’t . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . position of mark t
\k \K . . . . . . . . . . . . . . . . . . . . . a keyword, excluding digits :tags←- . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . print tag list /p/ ?p? . . . . . . . the next, previous line where p matches
:nˆT←- . . . . . . . . . . jump back to nth older tag in tag list +n -n . . . . . . . . . . . +n, −n to the preceding line number
\f \F . . . . . . . . . . . . . . . . . . . . a file name, excluding digits
\p \P . . . . . . . . . . . a printable character, excluding digits :npo←- . . . . . . . jump back from nth older tag in tag list
\s \S . . . . . . . . . . . . . . . . a white space, a non-white space :tl←- . . . . . . . . . . . . . . . . . . . . . . jump to last matching tag Miscellaneous
\e \t \r \b . . . . . . . . . . . . . . . . . . . hesci, htabi, h←-i, h←i ˆW{ :pt t←- . . . . . . . . . . . preview tag under cursor, tag t :sh←- :!c←- . . . start shell, execute command c in shell
\= * \+ . . . . match 0..1, 0..∞, 1..∞ of preceding atoms ˆW] . . . . . . . . . . . split window and show tag under cursor K . . . . . . . . . . . . . . . lookup keyword under cursor with man
\| . . . . . . . . . . . . . . . . . . . . . . . separate two branches (≡ or) ˆWz or :pc←- . . . . . . . . . . . . . . . . . close tag preview window :make←- . . . . . . start make, read errors and jump to first
\( \) . . . . . . . . . . . . . . . . . . . . group patterns into an atom :cn←- :cp←- . . . . . . . . . . display the next, previous error
:cl←- :cf←- . . . . . . . list all errors, read errors from file
Scrolling & multi-windowing ˆL ˆG . . . . . . . redraw screen, show filename and position
Offsets in search commands ˆE ˆY . . . . . . . . . . . . . . . . . . . . . . . . . . . . . scroll line up, down gˆG . . . show cursor column, line, and character position
n or +n . . . . . . . . . . . . . . . . . . . n line downward in column 1 ˆD ˆU . . . . . . . . . . . . . . . . . . . . . . scroll half a page up, down ga . . . . . . . . . show ASCII value of character under cursor
-n . . . . . . . . . . . . . . . . . . . . . . . . . n line upward in column 1 ˆF ˆB . . . . . . . . . . . . . . . . . . . . . . . . . . . . scroll page up, down gf. . . . . . . . . . . . .open file which filename is under cursor
e+n e-n . . . . . . . n characters right, left to end of match zt or z←- . . . . . . . . . . . . . set current line at top of window :redir>f ←- . . . . . . . . . . . . . . . . . . redirect output to file f
s+n s-n . . . . . . n characters right, left to start of match zz or z. . . . . . . . . . . . set current line at center of window
;sc . . . . . . . . . . . . . . . . . . execute search command sc next zb or z- . . . . . . . . . . . set current line at bottom of window
zh zl . . . . . . . . . . . . scroll one character to the right, left
zH zL . . . . . . . . . . . . . scroll half a screen to the right, left
Marks and motions ˆWs or :split←- . . . . . . . . . . . . . . . . . . . split window in two
mc . . . . . . . . . mark current position with mark c ∈ [a..Z] ˆWn or :new←-. . . . . . . . . . . . . . . .create new empty window
‘c ‘C . . . . . . . . . . . go to mark c in current, C in any file ˆWo or :on←- . . . . . . . make current window one on screen
‘0..9 . . . . . . . . . . . . . . . . . . . . . . . . . . . go to last exit position ˆWj ˆWk . . . . . . . . . . . . . . . . . move to window below, above
‘‘ ‘" . . . . . . . . . . go to position before jump, at last edit ˆWw ˆWˆW. . . . . . . . .move to window below, above (wrap)
‘[ ‘] . . . . . go to start, end of previously operated text
:marks←- . . . . . . . . . . . . . . . . . . . print the active marks list
:jumps←- . . . . . . . . . . . . . . . . . . . . . . . . . . print the jump list Ex commands (←-)
nˆO . . . . . . . . . . . . . . . go to nth older position in jump list :e f . . . . . . . edit file f , unless changes have been made
nˆI . . . . . . . . . . . . . . go to nth newer position in jump list :e! f . . . . edit file f always (by default reload current)
:wn :wN . . . . . . . . . write file and edit next, previous one
:n :N . . . . . . . . . . . . . . . . . . . . edit next, previous file in list
Key mapping & abbreviations :rw . . . . . . . . . . . . . . . . . . . . . . . write range r to current file
:map c e←-. . . . . . .map c 7→ e in normal & visual mode :rw f . . . . . . . . . . . . . . . . . . . . . . . . . . .write range r to file f
:map! c e←- . . . . map c 7→ e in insert & cmd-line mode :rw>>f . . . . . . . . . . . . . . . . . . . . . . . append range r to file f
:unmap c←- :unmap! c←- . . . . . . . . . . remove mapping c :q :q! . . . . . . quit & confirm, quit and discard changes
:mk f ←- . . . write current mappings, settings... to file f :wq or :x or ZZ . . . . . . . . . . . . . write to current file and exit This card may be freely distributed under the terms of the GNU
:ab c e←- . . . . . . . . . . . . . . . . . add abbreviation for c 7→ e hupi hdowni . . . . recall commands starting with current general public licence — Copyright c  by Laurent Grégoire
:ab c←- . . . . . . . . . . . . show abbreviations starting with c :r f . . . . . . . . . . . . . . insert content of file f below cursor hlaurent.gregoire@icam.fri — v1.2 — The author assumes no
:una c←- . . . . . . . . . . . . . . . . . . . . . . . remove abbreviation c :r! c . . . . . . . . insert output of command c below cursor responsability for any errors on this card.

You might also like