vi Editor: Replace Text from the Cursor Forward In the standard vi editor, which command puts you into overwrite (replace) mode so that typing replaces existing text from the cursor to the right?

Difficulty: Easy

Correct Answer: R

Explanation:


Introduction / Context:
vi is a modal editor: normal mode for commands, insert mode for insertion, and replace mode for overwriting. Choosing the right command speeds up edits, especially when you need to overwrite existing text starting at the cursor position.


Given Data / Assumptions:

  • Behavior of classic vi (and Vim in compatible mode).
  • Goal: replace characters as you type, beginning at the current cursor position.
  • User is familiar with normal-mode keystrokes.


Concept / Approach:
Pressing uppercase R enters replace mode. In this mode, each character you type overwrites the character under the cursor and then advances, effectively replacing text “to the right” until you exit the mode with Esc. This differs from single-character or line substitutions.


Step-by-Step Solution:
Position the cursor at the first character to overwrite.Press R to enter replace mode.Type the replacement text; existing characters are overwritten as you proceed.Press Esc to leave replace mode and return to normal mode.


Verification / Alternative check:
Try rX to see that lowercase r replaces only one character with X. Compare with C which changes (deletes) from the cursor to end-of-line and then enters insert mode, not replace mode.


Why Other Options Are Wrong:
r (Option A) replaces a single character only.s (Option C) deletes one character and enters insert mode (not continuous overwrite).S (Option D) substitutes the entire line (delete line, enter insert mode).


Common Pitfalls:

  • Using C when you actually want overwrite behavior (C deletes to EOL).
  • Forgetting to exit replace mode with Esc, leading to unintended overwrites.


Final Answer:
R

More Questions from Unix

Discussion & Comments

No comments yet. Be the first to comment!
Join Discussion