vimtricks.wiki Concise Vim tricks, one at a time.

How do I search forward but place the cursor at the end of the match?

Answer

/TODO/e

Explanation

Most users know /pattern, but fewer use search offsets to control where the cursor lands after the match. Adding /e is a precise navigation trick: Vim still searches for the same pattern, but it places the cursor on the end of the match instead of the beginning. This is valuable when your next operation targets trailing characters, punctuation, or suffixes.

How it works

  • /TODO searches forward for the next TODO
  • /e is an offset that moves the cursor to the end of that matched text
  • The search register (@/) still stores the same pattern, so n and N continue naturally

You are changing landing position, not the pattern itself.

Example

Given:

refactor TODO
ship TODO

From the start of the file, run:

/TODO/e

The cursor lands on the final O in TODO rather than the initial T. This makes immediate follow-up actions like a, x, or ;-style character finds more direct.

Tips

  • Use /b to land at the beginning explicitly when mixing offsets in complex workflows
  • Offsets compose with normal search, so you can still rely on n/N after the first jump
  • Pair this with :set hlsearch to keep full match visibility while landing exactly where edits should start

Next

How do I tune Vim diff so moved code blocks align more accurately?