vi editor navigation (current line search) In the classic vi editor, which motion finds and moves the cursor forward to the first occurrence of a specified character ch on the current line?

Difficulty: Easy

Correct Answer: fch

Explanation:


Introduction / Context:
Efficient navigation in the vi editor relies on single-keystroke motions. When you need to jump directly to a specific character ahead on the same line, vi provides concise commands that reduce cursor keystrokes and speed up edits in code and configuration files.


Given Data / Assumptions:

  • You are using vi (or Vim in compatible mode) in normal mode.
  • You want to move forward on the current line to the first occurrence of a character, denoted here as ch.
  • Character search is case-sensitive in vi motions.


Concept / Approach:
The motion f{char} moves the cursor forward to the next occurrence of {char} on the current line. The mnemonic is “find”. The related t{char} motion moves to the position just before {char} (“till”). You can repeat the last f/t search using ; to go forward again or , to go backward to the previous match.


Step-by-Step Solution:
Enter normal mode (press Esc if necessary).Type f followed by the target character, e.g., f( or f, or fa.The cursor jumps to the first matching character to the right on the same line.Use ; to move to the next occurrence or , to move to the previous one.


Verification / Alternative check:
Compare with tch (“till”): t, places the cursor before the comma rather than on it. If no match exists to the right, vi reports a beep/error and the cursor does not move.


Why Other Options Are Wrong:
tch (Option A) stops just before the character, not on it.rch (Option C) and ech (Option D) are not valid vi motions.None of the above (Option E) is incorrect because fch is the intended notation for f followed by ch.


Common Pitfalls:

  • Typing f then two characters; vi accepts only a single target character.
  • Forgetting to stay on the same line; these motions do not cross line breaks.
  • Confusing search motions (/) which scan multiple lines with f/t which are single-line motions.


Final Answer:
fch

More Questions from Unix

Discussion & Comments

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