├── bash-vi-editing-mode-cheat-sheet.pdf ├── bash-vi-editing-mode-cheat-sheet.tex ├── bash-vi-editing-mode-cheat-sheet.txt └── readme.txt /bash-vi-editing-mode-cheat-sheet.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pkrumins/bash-vi-editing-mode-cheat-sheet/c2c5a82396acfb6a02272754386543f33bdced96/bash-vi-editing-mode-cheat-sheet.pdf -------------------------------------------------------------------------------- /bash-vi-editing-mode-cheat-sheet.tex: -------------------------------------------------------------------------------- 1 | % Bash VI Editing Mode Shortcut Cheat Sheet 2 | % 3 | % by Peteris Krumins (peter@catonmat.net) 4 | % http://www.catonmat.net - good coders code, great reuse 5 | % 6 | % 2008.01.08 7 | % 8 | 9 | \documentclass{article} 10 | 11 | \usepackage[left=1.5cm,top=1cm,right=1.5cm,bottom=1cm,nohead,nofoot]{geometry} 12 | 13 | \usepackage[pdftex]{hyperref} 14 | \hypersetup{pdftitle={Bash VI Readline Editing Mode Shortcut Cheat Sheet}} 15 | \hypersetup{pdfauthor={Peteris Krumins (peter@catonmat.net)}} 16 | \hypersetup{pdfkeywords={cheat sheet, cheat sheat, cheet sheet, cheet sheat, terminal, command line, readline, read line, vi, keyboard, shortcut, shortcuts, unix, linux}} 17 | \hypersetup{pdfsubject={http://www.catonmat.net - good coders code, great reuse}} 18 | \hypersetup{colorlinks} 19 | 20 | \pagestyle{empty} 21 | 22 | % ----------------------------------------------------------------------- 23 | 24 | \begin{document} 25 | 26 | \begin{center} 27 | \Large Readline VI Editing Mode Cheat Sheet \\ 28 | \Large Default Keyboard Shortcuts for Bash 29 | \end{center} 30 | 31 | \vspace{0.4in} 32 | 33 | \renewcommand{\arraystretch}{1.2} 34 | \begin{tabular}{|p{4.5cm}|p{13cm}|} 35 | \hline 36 | \large\textbf{Shortcut} & \large\textbf{Description} \\ 37 | \hline 38 | \multicolumn{3}{|l|}{\small\it{Commands for Moving:}} \\ 39 | \hline 40 | \textbf{C-a} & beginning-of-line & Move to the beginning of line. \\ 41 | \hline 42 | \textbf{C-e} & end-of-line & Move to the end of line. \\ 43 | \hline\hline 44 | \large\textbf{Shortcut} & \large\textbf{Description} \\ 45 | \hline 46 | \multicolumn{2}{|l|}{\small\it{Switching to Command Mode:}} \\ 47 | \hline 48 | \textbf{ESC} & Switch to \textbf{command} mode. \\ 49 | \hline 50 | \multicolumn{2}{|l|}{\small\it{Commands for Entering Input mode:}} \\ 51 | \hline 52 | \textbf{i} & Insert before cursor. \\ 53 | \hline 54 | \textbf{a} & Insert after cursor. \\ 55 | \hline 56 | \textbf{I} & Insert at the beginning of line. \\ 57 | \hline 58 | \textbf{A} & Insert at the end of line. \\ 59 | \hline 60 | \textbf{c{\textless}movement command{\textgreater}} & Change text of a movement command \textbf{{\textless}movement command{\textgreater}} (see below). \\ 61 | \hline 62 | \textbf{C} & Change text to the end of line (equivalent to \textbf{c\$}). \\ 63 | \hline 64 | \textbf{cc} or \textbf{S} & Change current line (equivalent to \textbf{0c\$}). \\ 65 | \hline 66 | \textbf{s} & Delete a single character under the cursor and enter input mode (equivalent to \textbf{c[SPACE]}) . \\ 67 | \hline 68 | \textbf{r} & Replaces a single character under the cursor (without leaving command mode). \\ 69 | \hline 70 | \textbf{R} & Replaces characters under the cursor. \\ 71 | \hline 72 | \textbf{v} & Edit (and execute) the current command in a text editor (an editor in \$VISUAL and \$EDITOR variables or vi). \\ 73 | \hline 74 | \multicolumn{2}{|l|}{\small\it{Basic Movement Commands (in \textbf{command} mode):}} \\ 75 | \hline 76 | \textbf{l} or \textbf{SPACE} & Move one character right. \\ 77 | \hline 78 | \textbf{h} & Move one character left. \\ 79 | \hline 80 | \textbf{w} & Move one word or token right. \\ 81 | \hline 82 | \textbf{b} & Move one word or token left. \\ 83 | \hline 84 | \textbf{W} & Move one non-blank word right. \\ 85 | \hline 86 | \textbf{B} & Move one non-blank word left. \\ 87 | \hline 88 | \textbf{e} & Move to the end of the current word. \\ 89 | \hline 90 | \textbf{E} & Move to the end of the current non-blank word. \\ 91 | \hline 92 | \textbf{0} & Move to the beginning of line. \\ 93 | \hline 94 | \textbf{\^} & Move to the first non-blank character of line. \\ 95 | \hline 96 | \textbf{\$} & Move to the end of line. \\ 97 | \hline 98 | \textbf{\%} & Move to the corresponding opening/closing bracket (()'s, []'s and \{\}'s). \\ 99 | \hline 100 | \multicolumn{2}{|l|}{\small\it{Character Finding Commands (these are also Movement Commands):}} \\ 101 | \hline 102 | \textbf{f\textit{c}} & Move right to the next occurance of \textit{c}. \\ 103 | \hline 104 | \textbf{F\textit{c}} & Move left to the previous occurance of \textit{c}. \\ 105 | \hline 106 | \textbf{t\textit{c}} & Move right to the next occurance of \textit{c}, then one char backward. \\ 107 | \hline 108 | \textbf{T\textit{c}} & Move left to the previous occurance of \textit{c}, then one char forward. \\ 109 | \hline 110 | \textbf{;} & Redo the last character finding command. \\ 111 | \hline 112 | \textbf{,} & Redo the last character finding command in opposite direction. \\ 113 | \hline 114 | \textbf{\textbar} & Move to the \textit{n}-th column (you may specify the argument \textit{n} by typing it on number keys, for example, \textbf{20\textbar}). \\ 115 | \hline 116 | 117 | \end{tabular} 118 | 119 | %---------- examples 120 | 121 | %\begin{center} 122 | %\large Examples 123 | %\end{center} 124 | % 125 | %\begin{tabular}{|p{4.5cm}|p{13cm}|} 126 | % 127 | %\hline 128 | %\large\textbf{Example Shortcut} & \large\textbf{Example Description} \\ 129 | %\hline 130 | % 131 | %\hline 132 | % 133 | %\end{tabular} 134 | 135 | \vfill 136 | 137 | \framebox{\parbox{4.5in}{ 138 | A cheat sheet by \textbf{Peteris Krumins} (peter@catonmat.net), 2008. 139 | 140 | \href{http://www.catonmat.net}{http://www.catonmat.net} - good coders code, great reuse 141 | 142 | \vspace{2mm} 143 | \footnotesize{Released under GNU Free Document License.}}} 144 | 145 | 146 | %--------------------------------------------------------------------------- 147 | 148 | \newpage 149 | 150 | \mbox{} 151 | \begin{tabular}{|p{4.5cm}|p{13cm}|} 152 | \hline 153 | \multicolumn{2}{|l|}{\small\it{Deletion Commands:}} \\ 154 | \hline 155 | \textbf{x} & Delete a single character under the cursor. \\ 156 | \hline 157 | \textbf{X} & Delete a character before the cursor. \\ 158 | \hline 159 | \textbf{d{\textless}movement command{\textgreater}} & Delete text of a movement command \textbf{{\textless}movement command{\textgreater}} (see above). \\ 160 | \hline 161 | \textbf{D} & Delete to the end of the line (equivalent to \textbf{d\$}). \\ 162 | \hline 163 | \textbf{dd} & Delete current line (equivalent to \textbf{0d\$}). \\ 164 | \hline 165 | \textbf{CTRL-w} & Delete the previous word. \\ 166 | \hline 167 | \textbf{CTRL-u} & Delete from the cursor to the beginning of line. \\ 168 | \hline 169 | \multicolumn{2}{|l|}{\small\it{Undo, Redo and Copy/Paste Commands:}} \\ 170 | \hline 171 | \textbf{u} & Undo previous text modification. \\ 172 | \hline 173 | \textbf{U} & Undo all previous text modifications on the line. \\ 174 | \hline 175 | \textbf{.} & Redo the last text modification. \\ 176 | \hline 177 | \textbf{y{\textless}movement command{\textgreater}} & Yank a movement into buffer (copy). \\ 178 | \hline 179 | \textbf{yy} & Yank the whole line. \\ 180 | \hline 181 | \textbf{p} & Insert the yanked text at the cursor (paste). \\ 182 | \hline 183 | \textbf{P} & Insert the yanked text before the cursor. \\ 184 | \hline 185 | \multicolumn{2}{|l|}{\small\it{Commands for Command History:}} \\ 186 | \hline 187 | \textbf{k} & Move backward one command in history. \\ 188 | \hline 189 | \textbf{j} & Move forward one command in history. \\ 190 | \hline 191 | \textbf{G} & Move to the history line \textit{n} (you may specify the argument \textit{n} by typing it on number keys, for example, \textbf{15G}). \\ 192 | \hline 193 | \textbf{/\textit{string}} or \textbf{CTRL-r} & Search history backward for a command matching \textit{string}. \\ 194 | \hline 195 | \textbf{?\textit{string}} or \textbf{CTRL-s} & Search history forward for a command matching \textit{string} (remember that on most machines CTRL-s stops the output to the terminal (CTRL-q starts output) and you might need to change it with stty command). \\ 196 | \hline 197 | \textbf{n} & Repeat search in the same direction as previous. \\ 198 | \hline 199 | \textbf{N} & Repeat search in the opposite direction as previous. \\ 200 | \hline 201 | \multicolumn{2}{|l|}{\small\it{Completion Commands:}} \\ 202 | \hline 203 | \textbf{TAB} or \textbf{CTRL-i} or \textbf{=} & List possible completions. \\ 204 | \hline 205 | \textbf{*} & Insert all possible completions. \\ 206 | \hline 207 | \multicolumn{2}{|l|}{\small\it{Miscellaneous Commands:}} \\ 208 | \hline 209 | \textbf{$\sim$} & Invert the case of the character under cursor, and move a character right. \\ 210 | \hline 211 | \textbf{\#} & Prepend \textbf{\#} (comment character) to the line and send it to the history list. \\ 212 | \hline 213 | \textbf{\_} & Inserts the \textbf{n}-th word of the previous command in the current line. \\ 214 | \hline 215 | \textbf{0, 1, 2, ...} & Sets the numeric argument. \\ 216 | \hline 217 | \textbf{CTRL-v} & Insert a character literally (quoted insert). \\ 218 | \hline 219 | \textbf{CTRL-t} & Transpose (exchange) two characters. \\ 220 | \hline 221 | \end{tabular} 222 | 223 | \vspace{2mm} 224 | \begin{center} 225 | \large Examples and Tips 226 | \end{center} 227 | 228 | \begin{itemize} 229 | \item Some of the commands take a \textbf{{\textless}movement command{\textgreater}}. These commands apply the movement to themselves. For example, \textbf{d\$} would use \$ as a movement, which moves the cursor to the end of the line, thus, the whole \textbf{d\$} would delete text from the current cursor position to the end of the line. Another example, a command \textbf{c\textit{fA}} would use \textbf{fA} as a movement, which finds the next occurance of the character {\bf A}, thus, the whole command would change the line up to character {\bf A}. 230 | \item Use \textbf{CTRL-v} to insert character literally, for example, \textbf{CTRL-v CTRL-r} would insert CTRL-r in the command line. 231 | \item See \textbf{man bash}, \textbf{man readline}, and built in \textbf{bind} command for modifying the default behavior! 232 | \end{itemize} 233 | 234 | \vfill 235 | 236 | \framebox{\parbox{5in}{ 237 | A cheat sheet by \textbf{Peteris Krumins} (peter@catonmat.net), 2008. 238 | 239 | \href{http://www.catonmat.net}{http://www.catonmat.net} - good coders code, great reuse 240 | 241 | \vspace{2mm} 242 | \footnotesize{Released under GNU Free Document License.}}} 243 | 244 | \end{document} 245 | 246 | -------------------------------------------------------------------------------- /bash-vi-editing-mode-cheat-sheet.txt: -------------------------------------------------------------------------------- 1 | .---------------------------------------------------------------------------. 2 | | | 3 | | Readline VI Editing Mode | 4 | | Default Keyboard Shortcuts for Bash | 5 | | Cheat Sheet | 6 | | | 7 | '---------------------------------------------------------------------------' 8 | | Peteris Krumins (peter@catonmat.net), 2008.01.08 | 9 | | http://www.catonmat.net - good coders code, great reuse | 10 | | | 11 | | Released under the GNU Free Document License | 12 | '---------------------------------------------------------------------------' 13 | 14 | ======================== Keyboard Shortcut Summary ======================== 15 | 16 | .--------------.------------------------------------------------------------. 17 | | | | 18 | | Shortcut | Description | 19 | | | | 20 | '--------------'------------------------------------------------------------' 21 | | Switching to COMMAND Mode: | 22 | '--------------.------------------------------------------------------------' 23 | | ESC | Switch to command mode. | 24 | '--------------'------------------------------------------------------------' 25 | | Commands for Entering INPUT Mode: | 26 | '--------------.------------------------------------------------------------' 27 | | i | Insert before cursor. | 28 | '--------------+------------------------------------------------------------' 29 | | a | Insert after cursor. | 30 | '--------------+------------------------------------------------------------' 31 | | I | Insert at the beginning of line. | 32 | '--------------+------------------------------------------------------------' 33 | | A | Insert at the end of line. | 34 | '--------------+------------------------------------------------------------' 35 | | c | Change text of a movement command (see below). | 36 | '--------------+------------------------------------------------------------' 37 | | C | Change text to the end of line (equivalent to c$). | 38 | '--------------+------------------------------------------------------------' 39 | | cc or S | Change current line (equivalent to 0c$). | 40 | '--------------+------------------------------------------------------------' 41 | | s | Delete a single character under the cursor and enter input | 42 | | | mode (equivalent to c[SPACE]). | 43 | '--------------+------------------------------------------------------------' 44 | | r | Replaces a single character under the cursor (without | 45 | | | leaving command mode). | 46 | '--------------+------------------------------------------------------------' 47 | | R | Replaces characters under cursor. | 48 | '--------------+------------------------------------------------------------' 49 | | v | Edit (and execute) the current command in the text editor. | 50 | | | (an editor defined in $VISUAL or $EDITOR variables, or vi | 51 | '--------------'------------------------------------------------------------' 52 | | Basic Movement Commands (in command mode): | 53 | '--------------.------------------------------------------------------------' 54 | | h | Move one character right. | 55 | '--------------+------------------------------------------------------------' 56 | | l | Move one character left. | 57 | '--------------+------------------------------------------------------------' 58 | | w | Move one word or token right. | 59 | '--------------+------------------------------------------------------------' 60 | | b | Move one word or token left. | 61 | '--------------+------------------------------------------------------------' 62 | | W | Move one non-blank word right. | 63 | '--------------+------------------------------------------------------------' 64 | | B | Move one non-blank word left. | 65 | '--------------+------------------------------------------------------------' 66 | | e | Move to the end of the current word. | 67 | '--------------+------------------------------------------------------------' 68 | | E | Move to the end of the current non-blank word. | 69 | '--------------+------------------------------------------------------------' 70 | | 0 | Move to the beginning of line | 71 | '--------------+------------------------------------------------------------' 72 | | ^ | Move to the first non-blank character of line. | 73 | '--------------+------------------------------------------------------------' 74 | | $ | Move to the end of line. | 75 | '--------------+------------------------------------------------------------' 76 | | % | Move to the corresponding opening/closing bracket. | 77 | '--------------'------------------------------------------------------------' 78 | | Character Finding Commands (these are also Movement Commands): | 79 | '--------------.------------------------------------------------------------' 80 | | fc | Move right to the next occurance of char c. | 81 | '--------------+------------------------------------------------------------' 82 | | Fc | Move left to the previous occurance of c. | 83 | '--------------+------------------------------------------------------------' 84 | | tc | Move right to the next occurance of c, then one char | 85 | | | backward. | 86 | '--------------+------------------------------------------------------------' 87 | | Tc | Move left to the previous occurance of c, then one char | 88 | | | forward. | 89 | '--------------+------------------------------------------------------------' 90 | | ; | Redo the last character finding command. | 91 | '--------------+------------------------------------------------------------' 92 | | , | Redo the last character finding command in opposite | 93 | | | direction. | 94 | '--------------+------------------------------------------------------------' 95 | | | | Move to the n-th column (you may specify the argument n by | 96 | | | typing it on number keys, for example, 20|) | 97 | '--------------'------------------------------------------------------------' 98 | | Deletion Commands: | 99 | '--------------.------------------------------------------------------------' 100 | | x | Delete a single character under the cursor. | 101 | '--------------+------------------------------------------------------------' 102 | | X | Delete a character before the cursor. | 103 | '--------------+------------------------------------------------------------' 104 | | d | Delete text of a movement command (see above). | 105 | '--------------+------------------------------------------------------------' 106 | | D | Delete to the end of the line (equivalent to d$). | 107 | '--------------+------------------------------------------------------------' 108 | | dd | Delete current line (equivalent to 0d$). | 109 | '--------------+------------------------------------------------------------' 110 | | CTRL-w | Delete the previous word. | 111 | '--------------+------------------------------------------------------------' 112 | | CTRL-u | Delete from the cursor to the beginning of line. | 113 | '--------------'------------------------------------------------------------' 114 | | Undo, Redo and Copy/Paste Commands: | 115 | '--------------.------------------------------------------------------------' 116 | | u | Undo previous text modification. | 117 | '--------------+------------------------------------------------------------' 118 | | U | Undo all previous text modifications. | 119 | '--------------+------------------------------------------------------------' 120 | | . | Redo the last text modification. | 121 | '--------------+------------------------------------------------------------' 122 | | y | Yank a movement into buffer (copy). | 123 | '--------------+------------------------------------------------------------' 124 | | yy | Yank the whole line. | 125 | '--------------+------------------------------------------------------------' 126 | | p | Insert the yanked text at the cursor. | 127 | '--------------+------------------------------------------------------------' 128 | | P | Insert the yanked text before the cursor. | 129 | '--------------'------------------------------------------------------------' 130 | | Commands for Command History: | 131 | '--------------.------------------------------------------------------------' 132 | | k | Move backward one command in history. | 133 | '--------------+------------------------------------------------------------' 134 | | j | Move forward one command in history. | 135 | '--------------+------------------------------------------------------------' 136 | | G | Move to history line N (for example, 15G). | 137 | '--------------+------------------------------------------------------------' 138 | | /string or | Search history backward for a command matching string. | 139 | | CTRL-r | | 140 | '--------------+------------------------------------------------------------' 141 | | ?string or | Search history forward for a command matching string. | 142 | | CTRL-s | (Note that on most machines Ctrl-s STOPS the terminal | 143 | | | output, change it with `stty' (Ctrl-q to resume)). | 144 | '--------------+------------------------------------------------------------' 145 | | n | Repeat search in the same direction as previous. | 146 | '--------------+------------------------------------------------------------' 147 | | N | Repeat search in the opposite direction as previous. | 148 | '--------------'------------------------------------------------------------' 149 | | Completion commands: | 150 | '--------------.------------------------------------------------------------' 151 | | TAB or = or | List all possible completions. | 152 | | CTRL-i | | 153 | '--------------+------------------------------------------------------------' 154 | | * | Insert all possible completions. | 155 | '--------------'------------------------------------------------------------' 156 | | Miscellaneous commands: | 157 | '--------------.------------------------------------------------------------' 158 | | ~ | Invert case of the character under cursor and move a | 159 | | | character right. | 160 | '--------------+------------------------------------------------------------' 161 | | # | Prepend '#' (comment character) to the line and send it to | 162 | | | the history. | 163 | '--------------+------------------------------------------------------------' 164 | | _ | Inserts the n-th word of the previous command in the | 165 | | | current line. | 166 | '--------------+------------------------------------------------------------' 167 | | 0, 1, 2, ... | Sets the numeric argument. | 168 | '--------------+------------------------------------------------------------' 169 | | CTRL-v | Insert a character literally (quoted insert). | 170 | '--------------+------------------------------------------------------------' 171 | | CTRL-r | Transpose (exchange) two characters. | 172 | '--------------'------------------------------------------------------------' 173 | 174 | 175 | =========================================================================== 176 | 177 | .---------------------------------------------------------------------------. 178 | | Peteris Krumins (peter@catonmat.net), 2008.01.08. | 179 | | http://www.catonmat.net - good coders code, great reuse | 180 | | | 181 | | Released under the GNU Free Document License | 182 | '---------------------------------------------------------------------------' 183 | 184 | -------------------------------------------------------------------------------- /readme.txt: -------------------------------------------------------------------------------- 1 | Bourne again shell (bash) has two input editing modes - emacs and vi. This is 2 | vi editing mode cheat sheet. It lists all the keyboard shortcuts available 3 | in vi mode. It will make you much more productive in the shell. 4 | 5 | It was created by Peteris Krumins (peter@catonmat.net). 6 | His blog is at http://www.catonmat.net -- good coders code, great reuse. 7 | 8 | The cheat sheet is released under GNU Free Documentation License. 9 | 10 | The cheat sheet was created as supplementary material to my popular article 11 | "Working Productively in Bash's Vi Command Line Editing Mode". This article 12 | can be read on my website at the following address: 13 | 14 | http://www.catonmat.net/blog/bash-vi-editing-mode-cheat-sheet/ 15 | 16 | This cheat sheet is the 2nd in the series of working efficiently on the 17 | command line. 18 | 19 | The first article is "Bash Emacs Editing Mode Cheat Sheet": 20 | http://www.catonmat.net/blog/bash-emacs-editing-mode-cheat-sheet/ 21 | 22 | And the third is "The Definitive Guide to Bash Command Line History": 23 | http://www.catonmat.net/blog/the-definitive-guide-to-bash-command-line-history/ 24 | 25 | ------------------------------------------------------------------------------ 26 | 27 | The vi editing mode cheat sheet contains the following shortcuts: 28 | 29 | * Switching to command mode. 30 | * Commands for entering the input mode. 31 | * Basic movement commands. 32 | * Character finding commands. 33 | * Deletion commands. 34 | * Undo, redo, copy/paste commands. 35 | * Commands for shell history. 36 | * Completion commands. 37 | * Miscellaneous commands. 38 | 39 | It's available in .txt (ascii), .pdf and latex (.tex) formats. The latest 40 | version of this cheat sheet can always be downloaded here: 41 | 42 | .txt: http://www.catonmat.net/download/bash-vi-editing-mode-cheat-sheet.txt 43 | .pdf: http://www.catonmat.net/download/bash-vi-editing-mode-cheat-sheet.pdf 44 | .tex: http://www.catonmat.net/download/bash-vi-editing-mode-cheat-sheet.tex 45 | 46 | To create a new .pdf from latex's .tex, use pdflatex command: 47 | 48 | $ pdflatex bash-vi-editing-mode-cheat-sheet.tex 49 | 50 | This will produce bash-vi-editing-mode-cheat-sheet.pdf 51 | 52 | ------------------------------------------------------------------------------ 53 | 54 | 55 | Have fun and be more productive on command line! 56 | 57 | 58 | Sincerely, 59 | Peteris Krumins 60 | http://www.catonmat.net 61 | 62 | --------------------------------------------------------------------------------