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 the word but leaves vi in normal mode.
cwCorrect. cw changes the word and begins insertion.
Correct. cw changes the word and begins insertion.
ywIncorrect. yw copies the word without changing it.
Incorrect. yw copies the word without changing it.
wIncorrect. w only moves to the next word.
Incorrect. w only moves to the next word.
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操作 / 一時ファイル
- Command output formatting can vary slightly by distribution or tool version.
- Run the example in a temporary directory or process when possible.
Foundation review
Read the scope first
Check whether the command acts on the current shell, a new process, an existing process, or a file.
Verify the observable result
Use the supplied command and compare the output with the expected result.