How do I repeat the last change in Vim?
Answer
.
Explanation
The . (dot) command repeats the last change you made. It is one of the most powerful commands in Vim because it lets you apply the same edit multiple times with a single keystroke.
How it works
Any command that modifies the buffer counts as a "change" — including insertions, deletions, replacements, and indentation. After performing a change, pressing . replays that exact change at the current cursor position.
Example
To delete three separate words throughout a file:
- Move to the first word, press
dawto delete it - Move to the second word, press
.to delete it - Move to the third word, press
.again
Common use cases
- Delete the word under the cursor (
daw), find the next one (n), repeat (.) - Change a variable name with
ciw+ new name +<Esc>, then.on each occurrence - Add a semicolon with
A;+<Esc>, thenj.to add it to the next line
Tips
- Combine with search (
/patternthennto find,.to repeat the change) for a manual find-and-replace - The dot command includes the full insert mode session — from entering insert mode to pressing
<Esc> - Counts work too:
3.repeats the last change three times