What is the difference between cw and ciw when changing a word?
Answer
cw vs ciw
Explanation
The cw and ciw commands both change a word, but they behave differently depending on cursor position. Understanding the distinction is essential for precise editing and will save you from unexpected results.
How it works
cwchanges from the cursor position to the end of the current word. If the cursor is in the middle of a word, only the portion from the cursor onward is changed.ciwchanges the entire inner word under the cursor, regardless of where in the word the cursor is positioned.cwis technicallyc+w(change + word motion), whileciwisc+iw(change + inner word text object)
Example
Given the text with the cursor on the i in quick:
The quick brown fox
Pressing cw deletes only ick (from cursor to end of word) and enters insert mode:
The qu| brown fox
Pressing ciw instead deletes the entire word quick and enters insert mode:
The | brown fox
With ciw, cursor position within the word does not matter — the full word is always selected.
Another key difference
When the cursor is at the start of a word, cw and ciw produce nearly identical results. The difference only matters when the cursor is in the middle or end of a word. This is why many Vim users develop a habit of always using ciw — it is predictable regardless of cursor position.
Tips
- Prefer
ciwwhen you want to replace a whole word — it works consistently no matter where the cursor lands on the word - Prefer
cwwhen you intentionally want to change only the tail of a word, like correcting a suffix caw("a word") changes the word plus surrounding whitespace — useful when you want to remove the word and close the gap- The same logic applies to delete and yank:
diwvsdw,yiwvsyw dwdeletes the word and trailing whitespace, whilededeletes only to the end of the word. Butcwbehaves likece— this is a historical Vim quirk documented in:help cw- Text objects (
iw,aw,i",a(, etc.) are almost always more predictable than motions (w,e,b) when combined with operators — learning to default to text objects will make your editing more reliable - Combine
ciwwith.to repeat: change one word, move to the next target, and press.to perform the same full-word replacement