How Vim commands combine
color = "red"Start each example in Normal mode on red. The i" text object covers the text inside the quotes. The first key chooses the action.
- yi"
- Copy red into a Vim register.
- di"
- Delete red. The line becomes color = "".
- ci"
- Delete red and enter Insert mode between the quotes. Type blue and press <Esc> to get color = "blue".
Choose a combination
A motion or text object sets the range for an operator.
Delete the word under the cursor.
Type the replacement, then press <Esc> to return to Normal mode.
On whitespace, iw selects the whitespace. Word boundaries depend on 'iskeyword'.
Scale with counts
[count] + operator + [count] + target
- 3dw
- Delete across three word motions.
- d3w
- Put the count after the operator for the same range.
- 2d3w
- The counts multiply: delete across six word motions.
- 3dd
- dd deletes one line. 3dd deletes three.
Motion ranges depend on the starting cursor and line boundaries. Not every command accepts a count.
Small changes, different ranges
- dw
- On the same line, delete from the cursor to just before the next word.
- diw
- Delete the word under the cursor. On whitespace, delete the whitespace.
- daw
- Delete a word and the whitespace chosen by the around-word object.
- dt,
- Delete up to the next comma on the same line; keep the comma.
- df,
- Delete through the next comma; include the comma.
- ci"
- Replace the contents of double quotes while keeping the quotes.
- gUiw
- Make the current word uppercase.
- =ip
- Reindent the current paragraph using Vim’s indent settings.
Repeat and read the notation
After a change, move to another suitable target and press . to repeat it. Use u to undo. For a change operator, finish the inserted replacement with <Esc> first.
Ctrl-x means hold Control and press x. <Esc> and <Enter> name keys. {char}, {motion}, and similar braces in Reference are placeholders. In Ex command abbreviations such as :w[rite], square brackets mark optional letters.