Welcome to our website.

A Practical Vim Tutor Cheat Sheet by Chapter

Working in Ubuntu often means spending a lot more time in the terminal, and Vim quickly becomes one of those tools worth getting comfortable with. After going through vimtutor, the most useful commands can be grouped into a compact reference for day-to-day lookup.

Vim Tutor Chapter-by-Chapter Reference

Chapter 1: Basic Movement and Exiting

<table> <thead> <tr> <th>Command</th> <th>What it does</th> <th>Memory cue</th> </tr> </thead> <tbody> <tr> <td>h j k l</td> <td>Move left, down, up, right</td> <td>h is horizontal, j looks like a down arrow, k can be remembered as going up, l points right visually</td> </tr> <tr> <td>:q!</td> <td>Quit without saving</td> <td>quit + ! force</td> </tr> <tr> <td>:wq</td> <td>Save and quit</td> <td>write + quit</td> </tr> <tr> <td>x</td> <td>Delete the character under the cursor</td> <td>Like crossing something out</td> </tr> <tr> <td>i</td> <td>Insert before the cursor</td> <td>insert</td> </tr> <tr> <td>A</td> <td>Append at the end of the line</td> <td>Append; uppercase means the larger target: line end</td> </tr> </tbody> </table>

Chapter 2: Deleting and Undoing

<table> <thead> <tr> <th>Command</th> <th>What it does</th> <th>Memory cue</th> </tr> </thead> <tbody> <tr> <td>dw</td> <td>Delete to the end of a word</td> <td>delete + word</td> </tr> <tr> <td>d$</td> <td>Delete to the end of the line</td> <td>delete + $ line end</td> </tr> <tr> <td>dd</td> <td>Delete the whole line</td> <td>Double d for a full-line delete</td> </tr> <tr> <td>2w</td> <td>Move forward two words</td> <td>A number prefix repeats the motion</td> </tr> <tr> <td>2dw / d2w</td> <td>Delete two words</td> <td>The count can go before the operator or before the motion</td> </tr> <tr> <td>u</td> <td>Undo</td> <td>undo</td> </tr> <tr> <td>U</td> <td>Undo all changes on the current line</td> <td>Uppercase means a larger undo scope</td> </tr> <tr> <td>Ctrl+r</td> <td>Redo / undo the undo</td> <td>redo</td> </tr> </tbody> </table>

The central idea in this chapter is that d is an operator, while motions such as w and $ define the target. In Vim, many edits follow this pattern:

operator + motion = action

Chapter 3: Changing, Replacing, and Jumping Around

<table> <thead> <tr> <th>Command</th> <th>What it does</th> <th>Memory cue</th> </tr> </thead> <tbody> <tr> <td>r</td> <td>Replace one character</td> <td>replace; no need to press Esc afterward</td> </tr> <tr> <td>R</td> <td>Enter replace mode</td> <td>Uppercase means repeated replacement</td> </tr> <tr> <td>ce / cw</td> <td>Change to the end of a word</td> <td>change; like delete, but enters Insert mode afterward</td> </tr> <tr> <td>c$</td> <td>Change to the end of the line</td> <td>change + $</td> </tr> <tr> <td>Ctrl+g</td> <td>Show current file and position information</td> <td>get info</td> </tr> <tr> <td>G</td> <td>Jump to the last line of the file</td> <td>Go to end</td> </tr> <tr> <td>gg</td> <td>Jump to the first line of the file</td> <td>Lowercase form for the beginning</td> </tr> <tr> <td>行号G</td> <td>Jump to a specific line</td> <td>For example, 15G</td> </tr> <tr> <td>/pattern</td> <td>Search forward</td> <td>/ as the search direction</td> </tr> <tr> <td>?pattern</td> <td>Search backward</td> <td>? searches the opposite way</td> </tr> <tr> <td>n</td> <td>Go to the next match</td> <td>next</td> </tr> <tr> <td>N</td> <td>Go to the previous match</td> <td>Uppercase reverses the direction</td> </tr> <tr> <td>Ctrl+o</td> <td>Jump back to an older position</td> <td>old</td> </tr> <tr> <td>Ctrl+i</td> <td>Jump forward to a newer position</td> <td>in</td> </tr> </tbody> </table>

Chapter 4: Search, Replace, and External Commands

<table> <thead> <tr> <th>Command</th> <th>What it does</th> <th>Memory cue</th> </tr> </thead> <tbody> <tr> <td>:s/old/new</td> <td>Replace the first match on the current line</td> <td>substitute</td> </tr> <tr> <td>:s/old/new/g</td> <td>Replace all matches on the current line</td> <td>global within the line</td> </tr> <tr> <td>:#,#s/old/new/g</td> <td>Replace within a line range</td> <td>For example, :5,12s/old/new/g</td> </tr> <tr> <td>:%s/old/new/g</td> <td>Replace all matches in the whole file</td> <td>% means all lines</td> </tr> <tr> <td>:%s/old/new/gc</td> <td>Replace with confirmation</td> <td>confirm</td> </tr> <tr> <td>:!command</td> <td>Run an external command</td> <td>! indicates an external shell command</td> </tr> <tr> <td>:w filename</td> <td>Save as another file</td> <td>write to a file</td> </tr> <tr> <td>v + :w</td> <td>Save a selected range to a new file</td> <td>Visual mode defines the range</td> </tr> <tr> <td>:r filename</td> <td>Read a file and insert its contents</td> <td>read</td> </tr> <tr> <td>:r !command</td> <td>Insert the output of a command</td> <td>For example, :r !ls</td> </tr> </tbody> </table>

Chapter 5: More Editing Techniques

<table> <thead> <tr> <th>Command</th> <th>What it does</th> <th>Memory cue</th> </tr> </thead> <tbody> <tr> <td>o</td> <td>Open a new line below and enter Insert mode</td> <td>open below</td> </tr> <tr> <td>O</td> <td>Open a new line above and enter Insert mode</td> <td>Uppercase means the opposite direction</td> </tr> <tr> <td>a</td> <td>Insert after the cursor</td> <td>append; lowercase means a smaller position</td> </tr> <tr> <td>A</td> <td>Insert at the end of the line</td> <td>Uppercase means the larger target: line end</td> </tr> <tr> <td>e</td> <td>Move to the end of a word</td> <td>end of word</td> </tr> <tr> <td>y</td> <td>Copy, or yank</td> <td>yank</td> </tr> <tr> <td>yw</td> <td>Copy a word</td> <td>yank word</td> </tr> <tr> <td>yy / Y</td> <td>Copy the whole line</td> <td>yank yank</td> </tr> <tr> <td>p</td> <td>Paste after the cursor</td> <td>paste</td> </tr> <tr> <td>P</td> <td>Paste before the cursor</td> <td>Uppercase means before</td> </tr> <tr> <td>R</td> <td>Replace mode</td> <td>Overwrite multiple characters</td> </tr> </tbody> </table>

Chapter 6: Visual Mode and Multiple Files

<table> <thead> <tr> <th>Command</th> <th>What it does</th> <th>Memory cue</th> </tr> </thead> <tbody> <tr> <td>v</td> <td>Enter character-wise Visual mode</td> <td>visual</td> </tr> <tr> <td>V</td> <td>Enter line-wise Visual mode</td> <td>Uppercase means whole lines</td> </tr> <tr> <td>Ctrl+v</td> <td>Enter block Visual mode, useful for column selection</td> <td>Selects a rectangular block</td> </tr> <tr> <td>></td> <td>Indent the selected text</td> <td>Right arrow means move right</td> </tr> <tr> <td><</td> <td>Unindent the selected text</td> <td>Left arrow means move left</td> </tr> <tr> <td>o</td> <td>Switch to the other end of the selection in Visual mode</td> <td>other end</td> </tr> <tr> <td>:e filename</td> <td>Open another file</td> <td>edit</td> </tr> <tr> <td>:bn / :bnext</td> <td>Go to the next buffer</td> <td>buffer next</td> </tr> <tr> <td>:bp / :bprev</td> <td>Go to the previous buffer</td> <td>buffer previous</td> </tr> </tbody> </table>

Chapter 7: Help and Completion

<table> <thead> <tr> <th>Command</th> <th>What it does</th> <th>Memory cue</th> </tr> </thead> <tbody> <tr> <td>:help</td> <td>Open Vim help</td> <td>help</td> </tr> <tr> <td>F1</td> <td>Open help</td> <td>Standard help key</td> </tr> <tr> <td>:help cmd</td> <td>View help for a specific command</td> <td>For example, :help x</td> </tr> <tr> <td>Ctrl+w Ctrl+w</td> <td>Switch between windows</td> <td>window</td> </tr> <tr> <td>Ctrl+d</td> <td>Show command-line completion options</td> <td>display options</td> </tr> <tr> <td>Tab</td> <td>Complete a command</td> <td>Standard completion key</td> </tr> <tr> <td>Ctrl+n / Ctrl+p</td> <td>Autocomplete in Insert mode</td> <td>next / previous</td> </tr> </tbody> </table>

Core Vim Operators

<table> <thead> <tr> <th>Operator</th> <th>What it does</th> <th>Common motions or targets</th> </tr> </thead> <tbody> <tr> <td>d</td> <td>Delete</td> <td>w $ 0 e G, and more</td> </tr> <tr> <td>c</td> <td>Change: delete, then enter Insert mode</td> <td>Same motion style as d</td> </tr> <tr> <td>y</td> <td>Yank / copy</td> <td>Same motion style as d</td> </tr> <tr> <td>></td> <td>Indent</td> <td>Lines or selected regions</td> </tr> <tr> <td><</td> <td>Unindent</td> <td>Lines or selected regions</td> </tr> <tr> <td>=</td> <td>Auto-format</td> <td>Lines or selected regions</td> </tr> </tbody> </table>

The general pattern is:

[number] + operator + [number] + motion

Examples:

  • d2w = delete two words
  • 2yy = copy two lines

20 Commands Worth Using Every Day

<table> <thead> <tr> <th>Rank</th> <th>Command</th> <th>Typical use</th> </tr> </thead> <tbody> <tr> <td>1</td> <td>i / Esc</td> <td>Start editing / return to Normal mode</td> </tr> <tr> <td>2</td> <td>:wq / :q!</td> <td>Save and quit / quit without saving</td> </tr> <tr> <td>3</td> <td>dd / p</td> <td>Cut and paste a line</td> </tr> <tr> <td>4</td> <td>yy / p</td> <td>Copy and paste a line</td> </tr> <tr> <td>5</td> <td>u / Ctrl+r</td> <td>Undo / redo</td> </tr> <tr> <td>6</td> <td>w / b</td> <td>Jump by word</td> </tr> <tr> <td>7</td> <td>A / I</td> <td>Edit at the end / beginning of a line</td> </tr> <tr> <td>8</td> <td>r</td> <td>Quickly replace one character</td> </tr> <tr> <td>9</td> <td>x</td> <td>Delete one character</td> </tr> <tr> <td>10</td> <td>/ + n</td> <td>Search and jump through matches</td> </tr> <tr> <td>11</td> <td>G / gg</td> <td>Move to the end / beginning of the file</td> </tr> <tr> <td>12</td> <td>v + ></td> <td>Select text and indent it</td> </tr> <tr> <td>13</td> <td>:%s/a/b/g</td> <td>Replace throughout the whole file</td> </tr> <tr> <td>14</td> <td>:!</td> <td>Run an external command</td> </tr> <tr> <td>15</td> <td>Ctrl+g</td> <td>Check file and cursor position</td> </tr> <tr> <td>16</td> <td>o / O</td> <td>Open a new line below / above</td> </tr> <tr> <td>17</td> <td>dw / cw</td> <td>Delete / change a word</td> </tr> <tr> <td>18</td> <td>ce</td> <td>Change to the end of a word</td> </tr> <tr> <td>19</td> <td>yiw / diw</td> <td>Yank / delete the inner word</td> </tr> <tr> <td>20</td> <td>.</td> <td>Repeat the previous change</td> </tr> </tbody> </table>

Printable Quick Mnemonic

Movement: hjkl wbe 0$ ggG
Editing: iIaAoO rR x
Deleting: dd dw d$ D
Copying: yy yw pP
Undo: u Ctrl+r
Search: / ? nN
Replace: :s :%s
Save/Quit: :w :q :wq :q!

Keep this nearby while practicing. After a week of regular use, the most common commands usually start to feel automatic.

Related Posts