In vi normal mode, the cursor is at the start of a word.
Delete that word as a change operation and immediately enter insert mode.
Which key sequence is appropriate?
c is the change operator. Combining it with the w motion as cw removes the word and enters insert mode for replacement text.
Detailed explanation
ywIncorrect. yw yanks the word without changing it.
Incorrect. yw yanks the word without changing it.
dwIncorrect. dw deletes the word but remains in normal mode.
Incorrect. dw deletes the word but remains in normal mode.
cwCorrect. cw changes the word and enters insert mode.
Correct. cw changes the word and enters insert mode.
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.
printf 'old value\n' > sample.txt; vim -Nu NONE -n -es sample.txt -c 'execute "normal! 0cwnew\<Esc>"' -c 'wq'; cat sample.txtExpected result
new valueKey points
- c is the change operator
- w moves by a word
- 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.