
% VIM Quick Reference Card
% Copyright (c) 2002 Laurent Gregoire.
% TeX Format


% Note:  Comment the following line (\input outopt.tex) if you want
% to generate yourself the card, either in DVI or PDF format.
% Uncomment the three next lines for PDF generation.
% Command for DVI : tex vimqrc.tex
% Command for PDF : pdftex vimqrc.tex

\input outopt.tex

% \pdfoutput=1
% \pdfpageheight=21cm
% \pdfpagewidth=29.7cm

% Font definitions
\font\bigbf=cmb12
\font\smallrm=cmr8
\font\smalltt=cmtt8
\font\tinyit=cmmi5

\def\title#1{\hfil{\bf #1}\hfil\par\vskip 2pt\hrule}
\def\cm#1#2{{\tt#1}\dotfill#2\par}
\def\cn#1{\hfill$\lfloor$ #1\par}
\def\sect#1{\vskip 0.7cm {\it#1\/}\par}

% Characters definitions
\def\bs{$\backslash$}
\def\backspace{$\leftarrow$}
\def\ctrl{{\rm\char94}\kern-1pt}
\def\enter{$\hookleftarrow$}
\def\or{\thinspace{\tinyit{or}}\thinspace}
\def\key#1{$\langle${\rm{\it#1\/}}$\rangle$}
\def\rapos{\char125}
\def\lapos{\char123}
\def\bs{\char92}
\def\tild{\char126}

% Three columns definitions
\parindent 0pt
\nopagenumbers
\hoffset=-1.56cm
\voffset=-1.54cm
\newdimen\fullhsize
\fullhsize=27.9cm
\hsize=8.5cm
\vsize=19cm
\def\fullline{\hbox to\fullhsize}
\let\lr=L
\newbox\leftcolumn
\newbox\midcolumn
\output={
  \if L\lr
    \global\setbox\leftcolumn=\columnbox
    \global\let\lr=M
  \else\if M\lr
    \global\setbox\midcolumn=\columnbox
    \global\let\lr=R
  \else
    \tripleformat
    \global\let\lr=L
  \fi\fi
  \ifnum\outputpenalty>-20000
  \else
    \dosupereject
  \fi}
\def\tripleformat{
  \shipout\vbox{\fullline{\box\leftcolumn\hfil\box\midcolumn\hfil\columnbox}}
  \advancepageno}
\def\columnbox{\leftline{\pagebody}}

% Card content
% Header
%\hrule\vskip 3pt
\title{VIM QUICK REFERENCE CARD}

\sect{Basic movement}
\cm{h l k j}{character left, right; line up, down}
\cm{b w}{word/token left, right}
\cm{ge e}{end of word/token left, right}
\cm{\lapos\ \rapos}{beginning of previous, next paragraph}
\cm{( )}{beginning of previous, next sentence}
\cm{0 gm}{beginning, middle of line}
\cm{\^\ \$}{first, last character of line}
\cm{$n$G $n$gg}{line $n$, default the last, first}
\cm{$n$\%}{percentage $n$ of the file {\it($n$ must be provided)\/}}
\cm{$n|$}{column $n$ of current line}
\cm{\%}{match of next brace, bracket, comment, {\tt\#define}}
\cm{$n$H $n$L}{line $n$ from start, bottom of window}
\cm{M}{middle line of window}

\sect{Insertion \& replace $\to$ insert mode}
\cm{i a}{insert before, after cursor}
\cm{I A}{insert at beginning, end of line}
\cm{gI}{insert text in first column}
\cm{o O}{open a new line below, above the current line}
\cm{r$c$}{replace character under cursor with $c$}
\cm{gr$c$}{like {\tt r}, but without affecting layout}
\cm{R}{replace characters starting at the cursor}
\cm{gR}{like {\tt R}, but without affecting layout}
\cm{c$m$}{change text of movement command $m$}
\cm{cc\or S}{change current line}
\cm{C}{change to the end of line}
\cm{s}{change one character and insert}
\cm{\tild}{switch case and advance cursor}
\cm{g\tild{$m$}}{switch case of movement command $m$}
\cm{gu$m$ gU$m$}{lowercase, uppercase text of movement $m$}
\cm{$<$$m$ $>$$m$}{shift left, right text of movement $m$}
\cm{$n$$<$\kern-3pt$<$ $n$$>$\kern-3pt$>$}{shift $n$ lines left, right}

\sect{Deletion}
\cm{x X}{delete character under, before cursor}
\cm{d$m$}{delete text of movement command $m$}
\cm{dd D}{delete current line, to the end of line}
\cm{J gJ}{join current line with next, without space}
\cm{:$r$d\enter}{delete range $r$ lines}
\cm{:$r$d$x$\enter}{delete range $r$ lines into register $x$}

\sect{Insert mode}
\cm{\ctrl V$c$ \ctrl V$n$}{insert char $c$ literally, decimal value $n$}
% \cm{\ctrl V$n$}{insert decimal value of character}
\cm{\ctrl A}{insert previously inserted text}
\cm{\ctrl @}{same as {\tt\ctrl A} and stop insert $\to$ command mode}
\cm{\ctrl R$x$ \ctrl R\ctrl R$x$}{insert content of register $x$, literally}
\cm{\ctrl N \ctrl P}{text completion before, after cursor}
\cm{\ctrl W}{delete word before cursor}
\cm{\ctrl U}{delete all inserted character in current line}
\cm{\ctrl D \ctrl T}{shift left, right one shift width}
\cm{\ctrl K$c_1$$c_2$\or $c_1$\kern-1pt\backspace$c_2$}{enter digraph $\{c_1,c_2\}$}
\cm{\ctrl O$c$}{execute $c$ in temporary command mode}
\cm{\ctrl X\ctrl E \ctrl X\ctrl Y}{scroll up, down}
\cm{\key{esc}\or \ctrl[}{abandon edition $\to$ command mode}

\sect{Copying}
\cm{"$x$}{use register $x$ for next delete, yank, put}
\cm{:reg\enter}{show the content of all registers}
\cm{:reg $x$\enter}{show the content of registers $x$}
\cm{y$m$}{yank the text of movement command $m$}
\cm{yy\or Y}{yank current line into register}
\cm{p P}{put register after, before cursor position}
\cm{]p [p}{like {\tt p}, {\tt P} with indent adjusted}
\cm{gp gP}{like {\tt p}, {\tt P} leaving cursor after new text}

\sect{Advanced insertion}
\cm{g?$m$}{perform rot13 encoding on movement $m$}
\cm{$n$\ctrl A $n$\ctrl X}{$+n$, $-n$ to number under cursor}
\cm{gq$m$}{format lines of movement $m$ to fixed width}
\cm{:$r$ce $w$\enter}{center lines in range $r$ to width $w$}
\cm{:$r$le $i$\enter}{left align lines in range $r$ with indent $i$}
\cm{:$r$ri $w$\enter}{right align lines in range $r$ to width $w$}
\cm{!$m$$c$\enter}{filter lines of movement $m$ through command $c$}
\cm{$n$!!$c$\enter}{filter $n$ lines through command $c$}
\cm{:$r$!$c$\enter}{filter range $r$ lines through command $c$}

\sect{Visual mode}
\cm{v V \ctrl V}{start/stop highlighting characters, lines, block}
\cm{o}{exchange cursor position with start of highlighting}
\cm{gv}{start highlighting on previous visual area}
\cm{aw as ap}{select a word, a sentence, a paragraph}
\cm{ab aB}{select a block ( ), a block {\tt\lapos} {\tt\rapos}}

\vskip 1cm
\sect{Undoing, repeating \& registers}
\cm{u U}{undo last command, restore last changed line}
\cm{.\thinspace\thinspace\ctrl R}{repeat last changes, redo last undo}
\cm{$n$.\ }{repeat last changes with count replaced by $n$}
\cm{q$c$ q$C$}{record, append typed characters in register $c$}
\cm{q}{stop recording}
\cm{@$c$}{execute the content of register $c$}
\cm{@@}{repeat previous {\tt @} command}
\cm{:@$c$\enter}{execute register $c$ as an {\it Ex\/} command}
\cm{:$r$g/$p$/$c$\enter}{execute {\it Ex\/} command $c$ on range $r$}
\cn{where pattern $p$ matches}

\vskip -0.2cm
\sect{Complex movement}
\cm{- +}{line up, down on first non-blank character}
\cm{B W}{space-separated word left, right}
\cm{gE E}{end of space-separated word left, right}
\cm{$n$\_}{down $n-1$ line on first non-blank character}
\cm{g0}{beginning of {\it screen\/} line}
\cm{g\^\ g\$}{first, last character of {\it screen\/} line}
\cm{gk gj}{{\it screen\/} line up, down}
\cm{f$c$ F$c$}{next, previous occurence of character $c$}
\cm{t$c$ T$c$}{before next, previous occurence of $c$}
\cm{; ,}{repeat last {\tt fFtT}, in opposite direction}
\cm{[[ ]]}{start of section backward, forward}
\cm{[] ][}{end of section backward, forward}
\cm{[( ])}{unclosed (, ) backward, forward}
\cm{[\lapos\ ]\rapos}{unclosed {\tt\lapos}, {\tt\rapos} backward, forward}
\cm{[m ]m}{start of backward, forward {\it Java\/} method}
\cm{[\# ]\#}{unclosed {\tt\#if}, {\tt\#else}, {\tt\#endif} backward, forward}
\cm{[* ]*}{start, end of {\tt/* */} backward, forward}

\sect{Search \& substitution}
\cm{/$s$\enter\ ?$s$\enter}{search forward, backward for $s$}
\cm{/$s$/$o$\enter\ ?$s$?$o$\enter}{search fwd, bwd for $s$ with offset $o$}
\cm{n\or /\enter}{repeat forward last search}
\cm{N\or ?\enter}{repeat backward last search}
\cm{\# *}{search backward, forward for word under cursor}
\cm{g\# g*}{same, but also find partial matches}
\cm{gd gD}{local, global definition of symbol under cursor}
\cm{:$r$s/$f$/$t$/$x$\enter}{substitute $f$ by $t$ in range $r$}
\cn{$x:$ {\tt g}---all occurrences, {\tt c}---confirm changes}
\cm{:$r$s $x$\enter}{repeat substitution with new $r$ \& $x$}

\vskip1cm
\sect{Special characters in search patterns}
\cm{.\thinspace\thinspace\thinspace\ctrl\ \$}{any single character, start, end of line}
\cm{\bs$<$ \bs$>$}{start, end of word}
\cm{[$c_1$-$c_2$]}{a single character in range $c_1..c_2$}
\cm{[\ctrl$c_1$-$c_2$]}{a single character not in range}
\cm{\bs i \bs k \bs I \bs K}{an identifier, keyword; excl. digits}
\cm{\bs f \bs p \bs F \bs P}{a file name, printable char.; excl. digits}
\cm{\bs s \bs S}{a white space, a non-white space}
\cm{\bs e \bs t \bs r \bs b}{\key{esc}, \key{tab}, \key{\enter}, \key{$\gets$}}
\cm{\bs = * \bs +}{match $0..1$, $0..\infty$, $1..\infty$ of preceding atoms}
\cm{\bs$|$}{separate two branches ($\equiv$ {\it or\/})}
\cm{\bs( \bs)}{group patterns into an atom}
\cm{\bs \& \bs $n$}{the whole matched pattern, $n^{th}$ {\tt()} group}
\cm{\bs u \bs l}{next character made upper, lowercase}
\cm{\bs c \bs C}{ignore, match case on next pattern}

\sect{Offsets in search commands}
\cm{$n$\or +$n$}{$n$ line downward in column 1}
\cm{-$n$}{$n$ line upward in column 1}
\cm{e+$n$ e-$n$}{$n$ characters right, left to end of match}
\cm{s+$n$ s-$n$}{$n$ characters right, left to start of match}
\cm{;$sc$}{execute search command $sc$ next}

\sect{Marks and motions}
\cm{m$c$}{mark current position with mark $c\in[a..Z]$}
\cm{`$c$ `$C$}{go to mark $c$ in current, $C$ in any file}
\cm{`$0..9$}{go to last exit position}
\cm{`\/`  `\/"}{go to position before jump, at last edit}
\cm{`[ `]}{go to start, end of previously operated text}
\cm{:marks\enter}{print the active marks list}
\cm{:jumps\enter}{print the jump list}
\cm{$n$\ctrl O}{go to $n^{th}$ older position in jump list}
\cm{$n$\ctrl I}{go to $n^{th}$ newer position in jump list}

\sect{Key mapping \& abbreviations}
\cm{:map $c$ $e$\enter}{map $c\mapsto e$ in normal \& visual mode}
\cm{:map!\ $c$ $e$\enter}{map $c\mapsto e$ in insert \& cmd-line mode}
\cm{:unmap $c$\enter\ :unmap!\ $c$\enter}{remove mapping $c$}
\cm{:mk $f$\enter}{write current mappings, settings... to file $f$}
\cm{:ab $c$ $e$\enter}{add abbreviation for $c\mapsto e$}
\cm{:ab $c$\enter}{show abbreviations starting with $c$}
\cm{:una $c$\enter}{remove abbreviation $c$}

\sect{Tags}
\cm{:ta $t$\enter}{jump to tag $t$}
\cm{:$n$ta\enter}{jump to $n^{th}$ newer tag in list}
\cm{\ctrl ] \ctrl T}{jump to the tag under cursor, return from tag}
\cm{:ts $t$\enter}{list matching tags and select one for jump}
\cm{:tj $t$\enter}{jump to tag or select one if multiple matches}
\cm{:tags\enter}{print tag list}
\cm{:$n$po\enter\ :$n$\ctrl T\enter}{jump back from, to $n^{th}$ older tag}
\cm{:tl\enter}{jump to last matching tag}
\cm{\ctrl W\rapos\ :pt $t$\enter}{preview tag under cursor, tag $t$}
\cm{\ctrl W]}{split window and show tag under cursor}
\cm{\ctrl Wz\or :pc\enter}{close tag preview window}

\sect{Scrolling \& multi-windowing}
\cm{\ctrl E \ctrl Y}{scroll line up, down}
\cm{\ctrl D \ctrl U}{scroll half a page up, down}
\cm{\ctrl F \ctrl B}{scroll page up, down}
\cm{zt\or z\enter}{set current line at top of window}
\cm{zz\or z.\ }{set current line at center of window}
\cm{zb\or z-}{set current line at bottom of window}
\cm{zh zl}{scroll one character to the right, left}
\cm{zH zL}{scroll half a screen to the right, left}
\cm{\ctrl Ws\or :split\enter}{split window in two}
\cm{\ctrl Wn\or :new\enter}{create new empty window}
\cm{\ctrl Wo\or :on\enter}{make current window one on screen}
\cm{\ctrl Wj \ctrl Wk}{move to window below, above}
\cm{\ctrl Ww \ctrl W\ctrl W}{move to window below, above (wrap)}

\sect{Ex commands (\enter)}
\cm{:e $f$}{edit file $f$, unless changes have been made}
\cm{:e!\ $f$}{edit file $f$ always (by default reload current)}
\cm{:wn :wN}{write file and edit next, previous one}
\cm{:n :N}{edit next, previous file in list}
\cm{:$r$w}{write range $r$ to current file}
\cm{:$r$w $f$}{write range $r$ to file $f$}
\cm{:$r$w$>$\kern-3pt$>$$f$}{append range $r$ to file $f$}
\cm{:q :q!}{quit and confirm, quit and discard changes}
\cm{:wq\or :x\or ZZ}{write to current file and exit}
\cm{\key{up} \key{down}}{recall commands starting with current}
\cm{:r $f$}{insert content of file $f$ below cursor}
\cm{:r!\ $c$}{insert output of command $c$ below cursor}
\cm{:all}{open a window for each file in the argument list}
\cm{:args}{display the argument list}

\sect{Ex ranges}
\cm{, ;\ }{separates two lines numbers, set to first line}
\cm{$n$}{an absolute line number $n$}
\cm{.\thinspace\thinspace\thinspace\$}{the current line, the last line in file}
\cm{\% *}{entire file, visual area}
\cm{'$t$}{position of mark $t$}
\cm{/$p$/ ?$p$?}{the next, previous line where $p$ matches}
\cm{+$n$ -$n$}{$+n$, $-n$ to the preceding line number}

\sect{Folding}
\cm{zf$m$}{create fold of movement $m$}
\cm{:$r$fo}{create fold for range $r$}
\cm{zd zE}{delete fold at cursor, all in window}
\cm{zo zc zO zC}{open, close one fold; recursively}
\cm{[z ]z}{move to start, end of current open fold}
\cm{zj zk}{move down, up to start, end of next fold}

\sect{Miscellaneous}
\cm{:sh\enter\ :!$c$\enter}{start shell, execute command $c$ in shell}
\cm{K}{lookup keyword under cursor with {\tt man}}
\cm{:make\enter}{start {\tt make}, read errors and jump to first}
\cm{:cn\enter\ :cp\enter}{display the next, previous error}
\cm{:cl\enter\ :cf\enter}{list all errors, read errors from file}
\cm{\ctrl L \ctrl G}{redraw screen, show filename and position}
\cm{g\ctrl G}{show cursor column, line, and character position}
\cm{ga}{show A{\smallrm SCII} value of character under cursor}
\cm{gf}{open file which filename is under cursor}
\cm{:redir$>$$f$\enter}{redirect output to file $f$}
\cm{:mkview $[f]$}{save view configuration [to file $f$]}
\cm{:loadview $[f]$}{load view configuration [from file $f$]}
\cm{\ctrl @ \ctrl K \ctrl \_\ \bs\ F$n$ \ctrl F$n$}{unmapped keys}

% Footer
\vfill \hrule\smallskip
{\smallrm This card may be freely distributed under
the terms of the GNU general public licence ---
Copyright \copyright\ {\oldstyle 2003} by Laurent Gr\'egoire
$\langle${\smalltt laurent.gregoire@icam.fr}$\rangle$ --- v1.5 ---
The author assumes no responsibility for any errors on this card.
The latest version can be found at
{\smalltt http://tnerual.eriogerg.free.fr/}}

% Ending
\supereject
\if L\lr \else\null\vfill\eject\fi
\if L\lr \else\null\vfill\eject\fi
\bye

% EOF
