The Language of Editing
If you have used other text editors, you likely think of editing as selection followed by an action.
- Move mouse to start.
- Click and drag to select text.
- Press
BackspaceorCtrl+C.
In Vim, editing is a conversation. You tell the editor what to do using a grammatical structure similar to English: Verb + Noun.
đź§ The Formula
Examples:
- d + w = Delete Word
- c + $ = Change to End of Line
- y + ap = Copy Paragraph
1. The Operators (Verbs)
Operators are commands that wait for a motion to tell them what to operate on.
| Key | Name | Mnemonic | Description |
|---|---|---|---|
d |
Delete | Delete | Cuts text into a register (clipboard). |
c |
Change | Change | Deletes text and immediately enters Insert Mode. |
y |
Yank | Yank | Copies text into a register. |
> |
Indent | Shift | Shifts text to the right. |
< |
Outdent | Shift | Shifts text to the left. |
= |
Format | - | Auto-indents code. |
[!TIP] The
c(Change) operator is one of the most useful. It saves you a keystroke by combining “delete” and “insert”. Instead ofdwtheni, just typecw.
2. The Motions (Nouns)
Motions define the range of text the operator will affect. They answer the question: “From where the cursor is now, to where?”
Basic Motions
| Key | Name | Mnemonic | Movement |
|---|---|---|---|
w |
Word | Word | Start of next word. |
b |
Back | Back | Start of previous word. |
e |
End | End | End of current word. |
$ |
EOL | - | End of line. |
0 |
BOL | - | Start of line (column 0). |
^ |
Soft BOL | - | First non-whitespace char of line. |
G |
End File | Go | Last line of file. |
gg |
Start File | - | First line of file. |
Precision Motions
| Key | Description | Example |
|---|---|---|
f{char} |
Find occurrence of {char} forward |
df, (delete up to and including comma) |
t{char} |
Till occurrence of {char} forward |
ct. (change up to, but NOT including dot) |
[!NOTE]
fincludes the target character.tstops right before it.
3. Combining Them (Sentences)
Now we can form sentences.
d + w = Delete Word
Deletes from the cursor position to the start of the next word.
c + $ = Change to End
Deletes everything from cursor to the end of the line and puts you in Insert Mode.
y + G = Yank to End of File
Copies everything from the current line to the end of the file.
Doubling Operators
If you type an operator twice, it acts on the current line.
dd: Delete current line.cc: Change current line (clears line, keeps indentation, enters Insert).yy: Yank (copy) current line.
4. Quantifiers (Adjectives)
You can add numbers to multiply motions. This adds an “Adjective” to our sentence.
Structure: Operator + Count + Motion
d2w: Delete 2 words.c3w: Change 3 words.y4j: Copy current line and 4 lines down (5 lines total).
5. Interactive Motion Trainer
Practice forming Vim sentences. Type the command required to perform the action described.