In the vi editor on Unix/Linux, which command inserts text immediately to the left of the current cursor position (that is, before the cursor)?

Difficulty: Easy

Correct Answer: i

Explanation:


Introduction / Context:
The vi editor (and Vim) provides several concise insert commands for fast text editing. Knowing exactly where text will be inserted relative to the cursor prevents off-by-one mistakes and accelerates editing tasks in code, configuration files, and logs.


Given Data / Assumptions:

  • You are in Normal mode (press Esc to ensure).
  • You want to insert text before the character under the cursor.
  • Standard vi keybindings are active.


Concept / Approach:
The 'i' command enters Insert mode and places the insertion point immediately before the current cursor position. Other insert-like commands exist: 'a' appends after the cursor, 's' replaces the single character under the cursor and then inserts, and 'S' replaces the entire line. Choosing the correct command ensures the text lands exactly where intended.


Step-by-Step Solution:

Press Esc to return to Normal mode.Position the cursor on the target character.Press i to enter Insert mode.Type the new text, then press Esc to leave Insert mode.


Verification / Alternative check:
Compare behavior of 'i' vs 'a': 'i' inserts before the cursor; 'a' appends after. Use 'h' and 'l' to move left/right one character to confirm relative placement.


Why Other Options Are Wrong:

  • a: Inserts after the cursor (append), not before.
  • s: Deletes the current character and then inserts.
  • S: Deletes the entire line and then inserts at line start.
  • None of the above: Incorrect because 'i' is correct.


Common Pitfalls:
Remaining in Insert mode inadvertently, confusing 'i' and 'a', or expecting visual block behavior without using the proper visual modes.


Final Answer:
i

Discussion & Comments

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