In vi normal mode, the cursor is at the beginning of a word.
Delete that word and immediately type replacement text.
Which key sequence is appropriate?
c is the change operator; cw combines it with the word motion and enters insert mode after deleting the word.
Detailed explanation
dwIncorrect. dw deletes the word but leaves vi in normal mode.
Incorrect. dw deletes but leaves vi in normal mode.
cwCorrect. cw changes the word and begins insertion.
Correct. cw changes the word range and enters insert mode.
ywIncorrect. yw copies the word without changing it.
Incorrect. yw copies the word into a register and leaves the original.
wIncorrect. w only moves to the next word.
Incorrect. w only moves the cursor.
Try it yourself
An example you can run in a temporary verification environment.
tmp=$(mktemp); printf 'old value\n' >"$tmp"; vim -Nu NONE -n -es "$tmp" +'normal gg0cwnew' +wq; cat "$tmp"; rm -f "$tmp"Expected result
new valueKey points
- c means change
- w is a word motion
- cw enters insert mode
Notes
- Environment: Vim 9.x互換のvi操作 / 一時ファイル
- Use a temporary file and harmless edits when testing vi commands.
- Confirm the behavior on the target vi/Vim implementation.
Foundation review
Place the operation
Combining c with a motion changes the selected text and prepares immediate replacement input.
Check the side effect
Use a disposable word and observe the mode after cw versus dw.