\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{Max (maxbini)} \pdfinfo{ /Title (max-vim-cheatsheet.pdf) /Creator (Cheatography) /Author (Max (maxbini)) /Subject (Max VIM cheatsheet 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}{A3A3A3} \definecolor{LightBackground}{HTML}{F3F3F3} \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{Max VIM cheatsheet Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{Max (maxbini)} via \textcolor{DarkBackground}{\uline{cheatography.com/21458/cs/4138/}}} \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}Max (maxbini) \\ \uline{cheatography.com/maxbini} \\ \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Cheat Sheet}} \\ \vspace{-2pt}Published 21st May, 2015.\\ Updated 11th January, 2019.\\ 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} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{search \& replace}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{Basic search and replace \newline The :substitute command searches for a text pattern, and replaces it with a text string. There are many options, but these are what you probably want: \newline \newline :\%s/foo/bar/g \newline Find each occurrence of 'foo' (in all lines), and replace it with 'bar'. \newline :s/foo/bar/g \newline Find each occurrence of 'foo' (in the current line only), and replace it with 'bar'. \newline :\%s/foo/bar/gc \newline Change each 'foo' to 'bar', but ask for confirmation first. \newline :\%s/\textbackslash{}\textless{}foo\textbackslash{}\textgreater{}/bar/gc \newline Change only whole words exactly matching 'foo' to 'bar'; ask for confirmation. \newline :\%s/foo/bar/gci \newline Change each 'foo' (case insensitive due to the i flag) to 'bar'; ask for confirmation. \newline :\%s/foo\textbackslash{}c/bar/gc is the same because \textbackslash{}c makes the search case insensitive. \newline This may be wanted after using :set noignorecase to make searches case sensitive (the default). \newline :\%s/foo/bar/gcI \newline Change each 'foo' (case sensitive due to the I flag) to 'bar'; ask for confirmation. \newline :\%s/foo\textbackslash{}C/bar/gc is the same because \textbackslash{}C makes the search case sensitive. \newline This may be wanted after using :set ignorecase to make searches case insensitive. \newline \newline Search range: \newline \newline :s/foo/bar/g Change each 'foo' to 'bar' in the current line. \newline :\%s/foo/bar/g Change each 'foo' to 'bar' in all the lines. \newline :5,12s/foo/bar/g Change each 'foo' to 'bar' for all lines from line 5 to line 12 (inclusive). \newline :'a,'bs/foo/bar/g Change each 'foo' to 'bar' for all lines from mark a to mark b inclusive (see Note below). \newline :'\textless{},'\textgreater{}s/foo/bar/g When compiled with +visual, change each 'foo' to 'bar' for all lines within a visual selection. Vim automatically appends the visual selection range ('\textless{},'\textgreater{}) for any ex command when you select an area and enter :. Also, see Note below. \newline :.,\$s/foo/bar/g Change each 'foo' to 'bar' for all lines from the current line (.) to the last line (\$) inclusive. \newline :.,+2s/foo/bar/g Change each 'foo' to 'bar' for the current line (.) and the two next lines (+2). \newline :g/\textasciicircum{}baz/s/foo/bar/g Change each 'foo' to 'bar' in each line starting with 'baz'. \newline Note: As of Vim 7.3, substitutions applied to a range defined by marks or a visual selection (which uses a special type of marks '\textless{} and '\textgreater{}) are not bounded by the column position of the marks by default. Instead, Vim applies the substitution to the entire line on which each mark appears unless the \textbackslash{}\%V atom is used in the pattern like: :'\textless{},'\textgreater{}s/\textbackslash{}\%Vfoo/bar/g.} \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}{Delete}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{Cancellare \newline x X cancella carattere al, prima del cursore \newline dm cancella il testo del comando di movimento m \newline dd D cancella la riga, fino alla fine della riga corrente \newline J gJ unisci la riga corrente successiva, senza spazi \newline :rd↵ cancella il gruppo di righe r \newline :rdx↵ sposta il gruppo di righe r nel registro x} \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}{copying}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{"x usa registro x per la prossima cancellazione, copia \newline :reg↵ mostra il contenuto di tutti i registri \newline :reg x↵ mostra il contenuto del registro x \newline ym copia il testo del comando di movimento m \newline yy or Y copia la riga corrente nel registro \newline p P metti registro dopo, prima del cursore \newline {]}p {[}p come p, P con indentazione modificata \newline gp gP come p, P lasciando il cursore dopo nuovo testo} \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}{editing}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{{\bf{refresh file}} \newline ` :edit` \newline This means replace the end of line represented by \$ with the string |. \newline `:\%s/\$/|/` \newline delete blank lines \newline `:\%s,\textbackslash{}n\textbackslash{}n,\textasciicircum{}M,g` \newline `:g/\textasciicircum{}\$/d` \newline `:v/./d` \newline delete all lines that are empty or that contain only whitespace characters \newline `:g/\textasciicircum{}\textbackslash{}s*\$/d` \newline :v/\textbackslash{}S/d``} \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}{grepping \& sorting}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{grep \newline :vimgrep \newline sort string \newline :\{range\}sort u \newline sort number \newline :sort n \newline sort after "|" \newline :sort /\textasciicircum{}.*|/} \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}{cut \& paste}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{{\bf{REGISTERS}} \newline \newline {\bf{Normal registers}} \newline a-z \newline \newline {\bf{Clipboard}} \newline + \newline \newline {\bf{Numbered registers}} \newline 0 - last yanked text \newline 1 - 9 last 9 deleted chunks of text \newline \newline {\bf{Copy}} \newline "\textless{}register\textgreater{}y\textless{}motion\textgreater{} \newline {\bf{Paste}} \newline "\textless{}register\textgreater{}p \newline \newline {\bf{SYSTEM CLIPBOARD}} \newline {\bf{Copy}} \newline "+y\textless{}motion\textgreater{} \newline {\bf{Paste}} \newline "+p} \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}{buffer}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{The :b command can also take a substring of the name of the file \newline :b bar will switch to the bar file. \newline :b o will switch to the foo file. \newline :b a will give you an error because it could mean either bar or baz, but you can fix the name to be more specific with, for example, : ↑ r Enter. \newline \newline This command can also take a number, if you want to use that: \newline \newline :b 5} \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}{Insert Mode}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{" editing/moving within current insert (Really useful) \newline \textless{}C-U\textgreater{} : delete all entered \newline \textless{}C-W\textgreater{} : delete last word \newline \textless{}HOME\textgreater{}\textless{}END\textgreater{} : beginning/end of line \newline \textless{}C-LEFTARROW\textgreater{}\textless{}C-RIGHTARROW\textgreater{} : jump one word backwards/forwards \newline \textless{}C-X\textgreater{}\textless{}C-E\textgreater{},\textless{}C-X\textgreater{}\textless{}C-Y\textgreater{} : scroll while staying put in insert \newline -{}- \newline Modalita' inserimento \newline \textasciicircum{}Vc \textasciicircum{}Vn inserice car. c letterale, valore decimale di n \newline \textasciicircum{}A inserisce il testo precedentemente inserito \newline \textasciicircum{}@ come \textasciicircum{}A e va da modalita' inserimento → comandi \newline \textasciicircum{}Rx \textasciicircum{}R\textasciicircum{}Rx inserisce contenuto del registro x, letterale \newline \textasciicircum{}N \textasciicircum{}P completamento del testo prima, dopo il cursore \newline \textasciicircum{}W cancella la parola prima del cursore \newline \textasciicircum{}U cancella tutti i caratteri inseriti nella riga corrente \newline \textasciicircum{}D \textasciicircum{}T sposta a sx, dx della larghezza di uno shift \newline \textasciicircum{}Kc1c2 or c1←c2 digita diagramma \textbackslash{}c1,c2\textbackslash{} \newline \textasciicircum{}Oc esegue c in modalita' comandi temporanea \newline \textasciicircum{}X\textasciicircum{}E \textasciicircum{}X\textasciicircum{}Y scorri in su, giu' \newline \<esc\>\textbackslash{}o \textasciicircum{}{[} vai modal. inserimento → modal. comandi} \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}{duplicates}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{hilight duplicates \newline :syn clear Repeat | g/\textasciicircum{}\textbackslash{}(.{\emph{\textbackslash{})\textbackslash{}n\textbackslash{}ze\textbackslash{}\%(.}}\textbackslash{}n\textbackslash{}){\emph{\textbackslash{}1\$/exe 'syn match Repeat "\textasciicircum{}' . escape(getline('.'), '".\textasciicircum{}\$}}{[}{]}') . '\$"' | nohlsearch} \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}{moving}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{Movimenti base \newline h l k j un carattere a sx, dx, su, giu' \newline b w parola/token a sx, dx \newline ge e fine parola/token sx, dx \newline \{ \} inizio precedente/prossimo paragrafo \newline ( ) inizio precedente, prossima frase \newline 0 gm inizio, meta' riga \newline \textasciicircum{} \$ primo, ultimo carattere della riga \newline nG ngg riga n, default ultima, prima \newline n\% n percento del file (n deve essere indicato) \newline n| la colonna n della riga corrente \newline \% trova prossima parentesi, commento, \#define \newline nH nL riga n dall'inizio, fine della finestra \newline M alla riga di mezzo della finestra} \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}{Folding}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{zf\#j creates a fold from the cursor down \# lines. \newline zf/string creates a fold from the cursor to string . \newline zj moves the cursor to the next fold. \newline zk moves the cursor to the previous fold. \newline zo opens a fold at the cursor. \newline zO opens all folds at the cursor. \newline zm increases the foldlevel by one. \newline zM closes all open folds. \newline zr decreases the foldlevel by one. \newline zR decreases the foldlevel to zero -{}- all folds will be open. \newline zd deletes the fold at the cursor. \newline zE deletes all folds. \newline {[}z move to start of open fold. \newline {]}z move to end of open fold.} \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}{Changing Case}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{guu : lowercase line \newline gUU : uppercase line \newline Vu : lowercase line \newline VU : uppercase line \newline g\textasciitilde{}\textasciitilde{} : flip case line \newline vEU : Upper Case Word \newline vE\textasciitilde{} : Flip Case Word \newline ggguG : lowercase entire file} \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}{CR+LF}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{VI: visualizzare e rimuovere CR+LF (\textasciicircum{}M) \newline - per visualizzarli: \newline :e ++ff=unix \newline \newline - per visualizzarli di default: \newline set ff=unix \newline set fileformats=unix \newline \newline - per rimuoverli: \newline :\%s/\textasciicircum{}M\$//g \newline \newline Note that you should type \textasciicircum{}M by pressing ctrl-v and then ctrl-m.} \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}{insert}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{Inserisci \& rimpiazza → modalita' inserimento \newline i a inserisci prima, dopo il cursore \newline I A inserisci all'inizio, fine della riga \newline gI inserisci il testo nella prima colonna \newline o O inserisci nuova riga sotto, sopra riga corrente \newline rc rimpiazza il carattere al cursore con c \newline grc come r, ma vai in modalita' inserimento \newline R rimpiazza caratteri a partire dal cursore \newline gR come R, ma vai in mod. inserimento \newline cm cambia il testo del comando di movimento m \newline cc or S cambia la riga corrente \newline C cambia fino alla fine della riga \newline s cambia un carattere e vai in mod. inserimento \newline \textasciitilde{} scambia maiuscolo/minuscolo ad avanza il cursore \newline g\textasciitilde{}m scambia maiuscolo/minuscolo per cmd. mov. m \newline gum gUm minuscolo/maiuscolo testo cmd. mov. m \newline \<m \>m sposta sx, dx testo del comando di mov. m \newline n\<\< n\>\> sposta n righe a sx, dx} \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}{Insert (advanced)}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{Inserimento avanzato \newline g?m esegui codifica rot13 su comando movimento m \newline n\textasciicircum{}A n\textasciicircum{}X +n, -n del numero al cursore \newline gqm formatta riga del movimento m a larghezza fissa \newline :rce w↵ centra le righe nel gruppo r a larghezza w \newline :rle i↵ allinea a sx righe gruppo r con indent. i \newline :rri w↵ allinea a dx righe gruppo r a larghezza w \newline !mc↵ filtra righe cmd. movimento m con cmd. c \newline n!!c↵ filtra le righe n con il comando c \newline :r!c↵ filtra gruppo di righe r con il comando c} \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}{Macroing}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{per registrare la macro "a": \newline qa \newline \newline per eseguire la macro "a" \newline @a \newline \newline per ripetere l'ultima macro eseguita: \newline @@} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{2.4885 cm} x{2.4885 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{advanced}} \tn % Row 0 \SetRowColor{LightBackground} remove multiple spaces in a visual selection & release visual selection, then: :'\textless{},'\textgreater{}s/\textbackslash{}\%\textbackslash{}V\textbackslash{}s\textbackslash{}+/ /g \tn % Row Count 3 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} % That's all folks \end{multicols*} \end{document}