\input{../common/preamble} \begin{document} \raggedright \footnotesize \begin{multicols}{3} % multicol parameters \setlength{\premulticols}{1pt} \setlength{\postmulticols}{1pt} \setlength{\multicolsep}{1pt} \setlength{\columnsep}{2pt} \begin{center} \textbf{\Large{Vim Cheat Sheet}} \\ \end{center} ~~ Most commands listed are scalable by numbers (i.e. \textbf{4k} moves four lines up, \textbf{2db} deletes two words back). Also notice how most navigation commands extends the basic movement commands (\textbf{j}, \textbf{k}, \textbf{h} and \textbf{l}). \section{Movement} \begin{tabular}{@{}l>{\bfseries}l} One line down: & j \\ One line up: & k \\ One character left: & h \\ One character right: & l \\ One word left & b \\ One word right: & w \\ Top of page: & H \\ Middle of page: & M \\ Bottom of page: & L \\ Top of document: & gg \\ Bottom of document: & G \\ Next paragraph: & \} \\ Previous paragraph: & \{ \\ Line of last edit: & '. \\ Goto line 20: & :20 \\ Goto matching parenthesis: & \% \\ Start of line & 0 \\ First non-blank character of line: & $\widehat{}$ \\ End of line: & \$ \end{tabular} \section{Marks/Visual} \begin{tabular}{@{}l>{\bfseries}l} Set mark named \emph{x}: & mx \\ Goto beginning of line marked \emph{x}: & 'x \\ Show all marks: & :marks \\ Show mark named \emph{x}: & :marks x \\ Mark text (exit with: \textbf{Esc}): & v \\ Mark next \emph{10} words: & v10w \\ Indent marked text to the left: & \textless \\ Indent marked left to the right: & \textgreater \end{tabular} \section{Editing} \begin{tabular}{@{}l>{\bfseries}l} Copy marked text: & y \\ Delete marked text: & d \\ Indent marked text: & == \\ Delete character at cursor position: & x \\ Copy line: & yy \\ Delete line: & dd \\ Copy word: & yw \\ Delete word: & dw \\ Insert text at cursor position: & p \\ Tabulate file with current tab settings: & :retab \\ Disable text reformatting for inserts: & :set paste \\ Revert file as it where five minuets ago: & :earlier 5m \\ Copy from current position to mark \emph{x}: & y'x \\ Delete from current position to mark \emph{x}: & d'x \\ Convert between upper/lower case: & $\sim$ \end{tabular} \subsection{Vi/File Handling} \begin{tabular}{@{}l>{\bfseries}l} Open \emph{file.txt} for editing: & :e file.txt \\ Write current file: & :w \\ Write current buffer to \emph{file.txt}: & :w file.txt \\ Quit Vi: & :q \\ Save current file and quit Vi: & :wq \\ Quit, discarding changes since last save: & :q! \end{tabular} \subsection{Search/Replace} \begin{tabular}{@{}l>{\bfseries}l} Search for \emph{string}: & /string \\ Search for exact word \emph{vi} (i.e. not \emph{vim}): & /\textbackslash\textless vi\textbackslash\textgreater \\ Goto next match: & n \\ Replace first \emph{a} in line with \emph{b}: & :s/a/b/ \\ Replace all \emph{a} in line with \emph{b}: & :s/a/b/g \\ Replace first \emph{a} in file with \emph{b}: & :\%s/a/b/ \\ Replace all \emph{a} in file with \emph{b}: & :\%s/a/b/g \end{tabular} \section{Window Handling} \begin{tabular}{@{}l>{\bfseries}l} Horizontal split: & :split (or :sp) \\ Vertically split: & :vsplit (or :vsp) \\ Open \emph{file.txt} in split window: & sp file.txt \\ Close window: & Ctrl-w q \end{tabular} \subsection{Window Navigation} \begin{tabular}{@{}l>{\bfseries}l} One window up: & Ctrl-w k \\ One window down: & Ctrl-w j \\ One window left: & Ctrl-w h \\ One window right: & Ctrl-w l \end{tabular} \subsection{Size Windows} \begin{tabular}{@{}l>{\bfseries}l} Equally size windows: & Ctrl-w = \\ Reduce window size by one line: & Ctrl-w - \\ Increase window size by one line: & Ctrl-w + \end{tabular} \section{Code Folding} \begin{tabular}{@{}l>{\bfseries}l} Fold marked text: & zf \\ Fold down 5 lines: & zf4j \\ Fold up 5 lines: & zf4k \\ Fold to mark \emph{x}: & xf'x \\ Fold to \emph{string}: & zf/string \\ Fold to matching parenthesis: & zf\% \\ Open fold at cursor: & zo \\ Delete fold at cursor: & zd \\ Close fold at cursor: & zc \\ Open all folds: & zR \\ Delete all folds: & zE \\ Close all folds: & zM \end{tabular} \subsection{Folds Navigation} \begin{tabular}{@{}l>{\bfseries}l} Next fold: & zj \\ Previous fold: & zk \\ Start of open fold: & [z \\ End of open fold: & ]z \end{tabular} \section{Tabs} \begin{tabular}{@{}l>{\bfseries}l} Open new tab: & :tabnew \\ Close tab: & :tabclose \\ Goto first tab: & :tabfirst \\ Goto next tab: & :tabnext (or :tabn) \\ Goto previous tab: & :tabprevious (or :tabp) \\ Move tab to last pos: & :tabmove (or :tabm) \\ Move tab to pos \emph{n}: & :tabmove n \\ Diplay tabs: & :tabs \end{tabular} \textinfo[1.5] \end{multicols} \end{document}