How do I replace a word under the cursor?
Answer
ciw
Explanation
The ciw command deletes the inner word under the cursor and drops you into insert mode so you can type a replacement. It combines the c (change) operator with the iw (inner word) text object.
How it works
ctriggers the change operator (delete + enter insert mode)iwselects the inner word under the cursor, excluding surrounding whitespace
Example
Given the text:
The quick brown fox
With the cursor anywhere on quick, pressing ciw deletes the word and enters insert mode. Type slow to get:
The slow brown fox
Tips
- Your cursor can be anywhere on the word — beginning, middle, or end
- Use
caw("a word") to also consume one side of surrounding whitespace - Use
ciWto change a WORD (whitespace-delimited, includes punctuation) - Pair with
.to repeat the same replacement on another word