In vi normal mode, replace only the character under the cursor with X.
Do not remain in insert mode after the replacement.
Which key sequence is correct?
Normal-mode r replaces the character under the cursor with the next typed character and remains in normal mode.
Detailed explanation
xXIncorrect. x deletes the character and X then enters a separate command context.
Incorrect. x deletes the character and X then enters a separate command context.
sXIncorrect. s substitutes a character and enters insert mode.
Incorrect. s substitutes a character and enters insert mode.
RXIncorrect. R enters replace mode for a sequence of characters.
Incorrect. R enters replace mode for a sequence of characters.
rXCorrect. rX replaces the current character with X and returns to normal mode.
Correct. rX replaces the current character with X and returns to normal mode.
Try it yourself
An example you can run in a temporary verification environment.
printf 'cat\n' > sample.txt; vim -Nu NONE -n -es sample.txt -c 'normal! 0rX' -c 'wq'; cat sample.txtExpected result
XatKey points
- r replaces one character
- R starts continuous replace mode
- s deletes a character and 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.