vi text editor (Vim/vi classic): Which vi command replaces the single character under the cursor and then enters insert mode so you can type any number of replacement characters?

Difficulty: Easy

Correct Answer: s

Explanation:


Introduction / Context:
Efficient editing in vi/Vim relies on powerful single-keystroke commands. Knowing the difference between change, substitute, append, and insert is key to rapid text manipulation. Here, we focus on replacing exactly one character and then continuing to type new text seamlessly.



Given Data / Assumptions:

  • We are using classic vi keybindings.
  • Cursor is on the character to be replaced.
  • We want to replace that character and continue inserting any number of characters.


Concept / Approach:

The command s (substitute) deletes the character under the cursor and puts you into insert mode. You can then type any amount of text. By contrast, r replaces only one character and remains in normal mode; S substitutes the entire line; a appends after the cursor; i inserts before the cursor.



Step-by-Step Solution:

Position the cursor over the character to change.Press s. The character is deleted and the editor enters insert mode.Type the new text (any length).Press Esc to return to normal mode when done.Optionally use csw (in Vim) and other text objects for advanced cases.


Verification / Alternative check:

Compare s vs r: rx changes one character to x and stops; s deletes the character and keeps you inserting, which matches the requirement.



Why Other Options Are Wrong:

b: S substitutes the whole line, not a single character.

c: a appends after the cursor; it does not remove the original character.

d: i inserts before the cursor; the original character remains unless you delete it manually.

e: Not applicable because s is correct.



Common Pitfalls:

Using r instead of s when multiple characters are needed; forgetting to press Esc to leave insert mode; confusing S with s, which affects a vastly different scope.



Final Answer:

s

More Questions from Unix

Discussion & Comments

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