vi/vim search navigation: In the vi editor, which single-character command initiates a forward search for a text pattern from the current cursor position?

Difficulty: Easy

Correct Answer: /

Explanation:

Introduction / Context:Efficient navigation and searching are central to productivity in vi/vim. The editor uses concise keystrokes to start searches in the forward or backward direction and to repeat them without retyping the pattern.

Given Data / Assumptions:

  • You are in normal mode (not insert mode).
  • You want to search from the cursor forward through the buffer.
  • You will type a pattern after the initiating keystroke.

Concept / Approach:In vi, the forward search command is “/”. After pressing “/”, you type the pattern and press Enter. The backward search equivalent is “?”. To repeat the last search in the same direction, press “n”; to reverse direction, press “N”. The doubled forms “//” and “??” are not the defined initiators; the first slash or question mark begins the command, and the rest are treated as part of the pattern.

Step-by-Step Solution:

Ensure you are in normal mode (press Esc).Press “/” to start a forward search.Type your pattern (e.g., “error”) and press Enter.Use “n” to jump to the next occurrence, “N” for the previous occurrence.

Verification / Alternative check:Try “?” with the same pattern to verify that it searches backward; observe the difference in match direction while using n/N.

Why Other Options Are Wrong:? initiates backward search. // and ?? are not separate commands; the extra character becomes part of the search string. None: incorrect because “/” is correct.

Common Pitfalls:Remaining in insert mode; forgetting to press Enter after typing the pattern; misunderstanding n/N direction behavior.

Final Answer:/

More Questions from Unix

Discussion & Comments

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