vi/vim editing — delete the character under the cursor In vi/vim normal mode, which command deletes the single character directly beneath (under) the cursor?
-
Ax
-
BX
-
Cdd
-
DD
-
ENone of the above
Answer
Correct Answer: x
Explanation
Introduction / Context:Precise character-level edits are common when correcting typos. vi/vim provides single-keystroke deletion commands that work from normal mode without entering insert mode, enabling very fast text manipulation.
Given Data / Assumptions:
- We are in normal (command) mode.
- The goal is to remove exactly one character, the one under the cursor.
- No custom mappings are in place.
Concept / Approach:
The command x deletes the character under the cursor. Its uppercase counterpart, X, deletes the character to the left of the cursor (backspace-like). Other delete commands operate on larger text objects or ranges (for example, dd deletes the entire line, and D deletes from the cursor to the end of the line).
Step-by-Step Solution:
Press Esc to ensure normal mode.Position the cursor over the character to remove.Pressx to delete it.Optionally use a count: 3x deletes the next three characters under and after the cursor.Verification / Alternative check:
Type a sample word, place the cursor on a letter, press x, and observe it vanish. Try X to see the difference (deletes to the left). Use u to undo if you delete the wrong character.
Why Other Options Are Wrong:
- X: deletes the character to the left, not under the cursor.
- dd: deletes the whole current line.
- D: deletes from the cursor to end of line.
- None of the above: incorrect because
xis correct.
Common Pitfalls:
Being in insert mode and pressing x (which will just type the letter x); mixing up x and X; forgetting that counts speed up repeated deletions.
Final Answer:
x