vi text editor operations In the vi editor, which command deletes three words forward from the cursor position (treating punctuation and whitespace by vi's word rules)?

Difficulty: Easy

Correct Answer: 3 dw

Explanation:


Introduction / Context:
The vi editor (and its improved version, Vim) is ubiquitous on UNIX/Linux. Efficient editing depends on mastering operator + motion combinations. Deleting multiple words in one keystroke is a common task that highlights how counts and motions work together in vi's modal editing model.


Given Data / Assumptions:

  • We are in Normal mode (command mode) in vi.
  • We wish to delete a span defined by a word motion.
  • We need exactly three words removed starting at the cursor.


Concept / Approach:
In vi, d is the delete operator and w is the word motion (move to the start of the next word). Prefixing with a count multiplies the motion. Thus, 3dw or d3w deletes three words forward. The option shown as “3 dw” represents this combined form with a count of 3 applied to dw.


Step-by-Step Solution:
Determine the operator: d (delete).Determine the motion: w (word forward).Apply a count of 3: 3dw (equivalently d3w).Result: three words ahead of the cursor are removed and stored in a register.


Verification / Alternative check:
Try variants such as d3w, which performs the same action. For whole words including trailing space behavior, 3de or 3dW can be compared to understand the difference between word and WORD motions.


Why Other Options Are Wrong:
3$d: deletes from cursor to the end of line, not three words.3 x: deletes three characters, not words.3 dd: deletes three lines, not words.


Common Pitfalls:

  • Confusing word motions (w, e, b) with line motions (j, k, 0, $).
  • Using Uppercase W which treats non-space punctuation differently.
  • Not being in Normal mode; commands fail or insert text in Insert mode.


Final Answer:
3 dw

Discussion & Comments

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