\documentclass[10pt,a4paper]{article} % Packages \usepackage{fancyhdr} % For header and footer \usepackage{multicol} % Allows multicols in tables \usepackage{tabularx} % Intelligent column widths \usepackage{tabulary} % Used in header and footer \usepackage{hhline} % Border under tables \usepackage{graphicx} % For images \usepackage{xcolor} % For hex colours %\usepackage[utf8x]{inputenc} % For unicode character support \usepackage[T1]{fontenc} % Without this we get weird character replacements \usepackage{colortbl} % For coloured tables \usepackage{setspace} % For line height \usepackage{lastpage} % Needed for total page number \usepackage{seqsplit} % Splits long words. %\usepackage{opensans} % Can't make this work so far. Shame. Would be lovely. \usepackage[normalem]{ulem} % For underlining links % Most of the following are not required for the majority % of cheat sheets but are needed for some symbol support. \usepackage{amsmath} % Symbols \usepackage{MnSymbol} % Symbols \usepackage{wasysym} % Symbols %\usepackage[english,german,french,spanish,italian]{babel} % Languages % Document Info \author{Martinsos} \pdfinfo{ /Title (vim.pdf) /Creator (Cheatography) /Author (Martinsos) /Subject (Vim Cheat Sheet) } % Lengths and widths \addtolength{\textwidth}{6cm} \addtolength{\textheight}{-1cm} \addtolength{\hoffset}{-3cm} \addtolength{\voffset}{-2cm} \setlength{\tabcolsep}{0.2cm} % Space between columns \setlength{\headsep}{-12pt} % Reduce space between header and content \setlength{\headheight}{85pt} % If less, LaTeX automatically increases it \renewcommand{\footrulewidth}{0pt} % Remove footer line \renewcommand{\headrulewidth}{0pt} % Remove header line \renewcommand{\seqinsert}{\ifmmode\allowbreak\else\-\fi} % Hyphens in seqsplit % This two commands together give roughly % the right line height in the tables \renewcommand{\arraystretch}{1.3} \onehalfspacing % Commands \newcommand{\SetRowColor}[1]{\noalign{\gdef\RowColorName{#1}}\rowcolor{\RowColorName}} % Shortcut for row colour \newcommand{\mymulticolumn}[3]{\multicolumn{#1}{>{\columncolor{\RowColorName}}#2}{#3}} % For coloured multi-cols \newcolumntype{x}[1]{>{\raggedright}p{#1}} % New column types for ragged-right paragraph columns \newcommand{\tn}{\tabularnewline} % Required as custom column type in use % Font and Colours \definecolor{HeadBackground}{HTML}{333333} \definecolor{FootBackground}{HTML}{666666} \definecolor{TextColor}{HTML}{333333} \definecolor{DarkBackground}{HTML}{000000} \definecolor{LightBackground}{HTML}{F7F7F7} \renewcommand{\familydefault}{\sfdefault} \color{TextColor} % Header and Footer \pagestyle{fancy} \fancyhead{} % Set header to blank \fancyfoot{} % Set footer to blank \fancyhead[L]{ \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{C} \SetRowColor{DarkBackground} \vspace{-7pt} {\parbox{\dimexpr\textwidth-2\fboxsep\relax}{\noindent \hspace*{-6pt}\includegraphics[width=5.8cm]{/web/www.cheatography.com/public/images/cheatography_logo.pdf}} } \end{tabulary} \columnbreak \begin{tabulary}{11cm}{L} \vspace{-2pt}\large{\bf{\textcolor{DarkBackground}{\textrm{Vim Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{Martinsos} via \textcolor{DarkBackground}{\uline{cheatography.com/116342/cs/21764/}}} \end{tabulary} \end{multicols}} \fancyfoot[L]{ \footnotesize \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{LL} \SetRowColor{FootBackground} \mymulticolumn{2}{p{5.377cm}}{\bf\textcolor{white}{Cheatographer}} \\ \vspace{-2pt}Martinsos \\ \uline{cheatography.com/martinsos} \\ \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Cheat Sheet}} \\ \vspace{-2pt}Published 15th February, 2020.\\ Updated 17th February, 2020.\\ Page {\thepage} of \pageref{LastPage}. \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Sponsor}} \\ \SetRowColor{white} \vspace{-5pt} %\includegraphics[width=48px,height=48px]{dave.jpeg} Measure your website readability!\\ www.readability-score.com \end{tabulary} \end{multicols}} \begin{document} \raggedright \raggedcolumns % Set font size to small. Switch to any value % from this page to resize cheat sheet text: % www.emerson.emory.edu/services/latex/latex_169.html \footnotesize % Small font. \begin{multicols*}{3} \begin{tabularx}{5.377cm}{x{1.14471 cm} x{3.83229 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Motions}} \tn % Row 0 \SetRowColor{LightBackground} h, j, k, l & one char (left, down, up, right) \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} 0, \textasciicircum{} & line start (column 0, first char) \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} \$ & line end \tn % Row Count 5 (+ 1) % Row 3 \SetRowColor{white} f\textless{}char\textgreater{} & to next \textless{}char\textgreater{} in line \tn % Row Count 6 (+ 1) % Row 4 \SetRowColor{LightBackground} t\textless{}char\textgreater{} & f\textless{}char\textgreater{}h \tn % Row Count 7 (+ 1) % Row 5 \SetRowColor{white} T\textless{}char\textgreater{} & t\textless{}char\textgreater{} but backwards \tn % Row Count 8 (+ 1) % Row 6 \SetRowColor{LightBackground} F\textless{}char\textgreater{} & f\textless{}char\textgreater{} but backwards \tn % Row Count 9 (+ 1) % Row 7 \SetRowColor{white} w, e & next word (start, end) \tn % Row Count 10 (+ 1) % Row 8 \SetRowColor{LightBackground} b & prev word (start) \tn % Row Count 11 (+ 1) % Row 9 \SetRowColor{white} W, E, B & stronger "w", "e", "b" \tn % Row Count 12 (+ 1) % Row 10 \SetRowColor{LightBackground} (, ) & start/end of sentence \tn % Row Count 13 (+ 1) % Row 11 \SetRowColor{white} \{, \} & start/end of paragraph \tn % Row Count 14 (+ 1) % Row 12 \SetRowColor{LightBackground} \% & first or matching parenth \tn % Row Count 15 (+ 1) % Row 13 \SetRowColor{white} gg, G & file start, file end \tn % Row Count 16 (+ 1) % Row 14 \SetRowColor{LightBackground} Ctrl-u/d & half screen up/down \tn % Row Count 17 (+ 1) % Row 15 \SetRowColor{white} :\textless{}num\textgreater{} & jump to line \tn % Row Count 18 (+ 1) % Row 16 \SetRowColor{LightBackground} \textless{}num\textgreater{}G & :\textless{}num\textgreater{} \tn % Row Count 19 (+ 1) % Row 17 \SetRowColor{white} Ctrl-o & undo movement \tn % Row Count 20 (+ 1) % Row 18 \SetRowColor{LightBackground} /\textless{}str\textgreater{} & search forward in file \tn % Row Count 21 (+ 1) % Row 19 \SetRowColor{white} * & /\textless{}word\_at\_position\textgreater{} \tn % Row Count 22 (+ 1) % Row 20 \SetRowColor{LightBackground} ?\textless{}str\textgreater{} & search backward in file \tn % Row Count 23 (+ 1) % Row 21 \SetRowColor{white} H, M, L & first/middle/last line on screen \tn % Row Count 25 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{There are more motions, but these are the basic ones. \newline \newline When used alone, motion moves the cursor. \newline It can also be used with operators. \newline \newline When it makes sense, you can prefix motion with a count: e.g. "3tg" moves to third occurrence of g. \newline \newline ";" after "t \textless{}char\textgreater{}" or "f \textless{}char\textgreater{}" does one more search. \newline "n" is next and "N" is previous when doing search with "/" or "?".} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Commands (Substitute)}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{`:\textless{}range\textgreater{}s/\textless{}old\textgreater{}/\textless{}new\textgreater{}/{[}flags{]}` \newline % Row Count 1 (+ 1) `range` -\textgreater{} nothing (in line), `\#,\#` (between lines), `\%` (whole file). \newline % Row Count 3 (+ 2) `flags` -\textgreater{} `g` (all occurrences), `c` (ask for confirmation), ... \newline % Row Count 5 (+ 2) `:s/thee/the` -\textgreater{} in line, first occurrence \newline % Row Count 6 (+ 1) `:1,10s/thee/the/g` -\textgreater{} from lines 1 to 10, all occurrences \newline % Row Count 8 (+ 2) `:\%s/thee/the/gc` -\textgreater{} whole file, all occurrences, ask for confirmation% Row Count 10 (+ 2) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Concept: extending}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{Listed here are motions, operators, text-objects and commands that come with vim. However, plugins (or you) can define new ones, bringing even more options!% Row Count 4 (+ 4) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{p{0.4977 cm} x{4.4793 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Operators}} \tn % Row 0 \SetRowColor{LightBackground} c & change (delete and enter insert mode) \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} d & delete \tn % Row Count 3 (+ 1) % Row 2 \SetRowColor{LightBackground} y & yank (copy) \tn % Row Count 4 (+ 1) % Row 3 \SetRowColor{white} gu & make lowercase \tn % Row Count 5 (+ 1) % Row 4 \SetRowColor{LightBackground} gU & make uppercase \tn % Row Count 6 (+ 1) % Row 5 \SetRowColor{white} g\textasciitilde{} & toggle case \tn % Row Count 7 (+ 1) % Row 6 \SetRowColor{LightBackground} \textgreater{} & shift right \tn % Row Count 8 (+ 1) % Row 7 \SetRowColor{white} \textless{} & shift left \tn % Row Count 9 (+ 1) % Row 8 \SetRowColor{LightBackground} gq & text formatting \tn % Row Count 10 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{There are few other operators, but they are not used much. \newline \newline Operators can be used as: \newline {[}count{]}operator({[}count{]}(motion | text-object)) \newline e.g. d, 3d, d\$, dw, d3w, 2d3w . \newline \newline Combining operator with motion executes operator from current point to point where motion takes us. \newline Combining operator with text object executes operator on that text object. \newline Numbers (count) execute operator multiple times. \newline \newline Typing an operator twice, e.g. dd or \textless{}\textless{}, usually executes the operator on current line.} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{p{0.59724 cm} x{4.37976 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Commands (Change/Insert)}} \tn % Row 0 \SetRowColor{LightBackground} i, I & insert at point / line start \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} a, A & append after point / line end \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} o, O & open line below / above \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} r, R & rewrite one / many char(s) \tn % Row Count 4 (+ 1) % Row 4 \SetRowColor{LightBackground} C & c\$ \tn % Row Count 5 (+ 1) % Row 5 \SetRowColor{white} cc & c\_ \tn % Row Count 6 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{All these commands enter insert mode.} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{1.19448 cm} x{3.78252 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Commands (:)}} \tn % Row 0 \SetRowColor{LightBackground} :!\textless{}cmd\textgreater{} & executes in external shell \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} :wqa & save all files and quit \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} :h\textless{}smth\textgreater{} & help \tn % Row Count 3 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Concept: composing}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{One of the best things in vim is composing its operators with motions and text-objects! Commands can't be composed. \newline % Row Count 3 (+ 3) Here we will list some examples (check "Operators" for exact definition of composition): \newline % Row Count 5 (+ 2) di( -\textgreater{} delete all inside (). \newline % Row Count 6 (+ 1) 3tp or tp;; -\textgreater{} move to third occurence of p in line. \newline % Row Count 8 (+ 2) cip -\textgreater{} delete current paragraph and enter insert mode. \newline % Row Count 10 (+ 2) \textless{}2ib -\textgreater{} shift current block two times left.% Row Count 11 (+ 1) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{1.89126 cm} x{3.08574 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Text objects}} \tn % Row 0 \SetRowColor{LightBackground} w & word \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} s & sentence \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} p & paragraph \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} ', ", ` & quotes \tn % Row Count 4 (+ 1) % Row 4 \SetRowColor{LightBackground} (, {[}, \{, \textless{} & parentheses \tn % Row Count 5 (+ 1) % Row 5 \SetRowColor{white} t & tag \tn % Row Count 6 (+ 1) % Row 6 \SetRowColor{LightBackground} \_ & current line (*) \tn % Row Count 7 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{Text objects are not to be used alone, but in combination with e.g. operators. \newline \newline Text objects can be combined with modifiers "a" (around) and "i" (inside) to create new text objects, e.g. iw (word we are inside of), or aw (word and surrounding spaces). \newline \newline (*) \_ is not really a text object, but it behaves mostly like one.} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{p{0.54747 cm} x{4.42953 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Commands (Deletion)}} \tn % Row 0 \SetRowColor{LightBackground} x, X & delete one char (after, before) \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} D & d\$ \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} dd & d\_ \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} J & join current with next line \tn % Row Count 4 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{p{0.94563 cm} x{4.03137 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Commands (Visual)}} \tn % Row 0 \SetRowColor{LightBackground} v & select from point \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} V & select from line \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} Ctrl-v & select from point as block \tn % Row Count 3 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{All these commands enter visual mode.} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{1.54287 cm} x{3.43413 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Commands (Other)}} \tn % Row 0 \SetRowColor{LightBackground} yy & y\_ \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} p & paste \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} . & repeat last command \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} u & undo \tn % Row Count 4 (+ 1) % Row 4 \SetRowColor{LightBackground} Ctrl-r & redo \tn % Row Count 5 (+ 1) % Row 5 \SetRowColor{white} zz & center screen on point \tn % Row Count 6 (+ 1) % Row 6 \SetRowColor{LightBackground} za, zm, zr & code folding \tn % Row Count 7 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Concept: modes}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{While in normal mode, we can do all the fun stuff: commands, operators, movements, and entering other modes. \newline % Row Count 3 (+ 3) While in insert mode, we are inserting text. \newline % Row Count 4 (+ 1) While in visual mode, we are selecting text.% Row Count 5 (+ 1) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Credits}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{These resources helped a lot in creating this cheat sheet: \newline % Row Count 2 (+ 2) - \seqsplit{http://ismail.badawi.io/blog/2014/04/23/the-compositional-nature-of-vim/} \newline % Row Count 4 (+ 2) - \seqsplit{https://takac.github.io/2013/01/30/vim-grammar/}% Row Count 5 (+ 1) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} % That's all folks \end{multicols*} \end{document}