In the vi editor, which command searches for a pattern in the forward direction from the current cursor position?

Difficulty: Easy

Correct Answer: /

Explanation:

Introduction / Context:Searching text efficiently is central to navigating in vi/Vim. Different search commands look forward or backward, and knowing the right one for forward search saves significant time.

Given Data / Assumptions:

  • You are in normal mode in vi/Vim.
  • You want to search forward in the file from the cursor location.

Concept / Approach:

The / command starts a forward search. After typing /pattern, pressing Enter will move the cursor to the next occurrence of 'pattern' after the cursor. Typing n repeats the search forward; N repeats it in the opposite direction.

Step-by-Step Solution:

Enter normal mode.Type /pattern and press Enter.The cursor jumps to the next match in forward direction.Use n to repeat search forward, N to reverse.

Verification / Alternative check:

Compare with ?pattern, which searches backward. Try on a sample file with repeated words to confirm direction.

Why Other Options Are Wrong:

  • ??: invalid, not a vi command.
  • //: repeats last search, does not initiate.
  • ?: backward search.
  • None: incorrect because / is correct.

Common Pitfalls:

  • Confusing / with ? for direction.
  • Forgetting to press Enter after typing the pattern.

Final Answer:

/.

Discussion & Comments

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