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
/TODOsearches forward for the nextTODO/eis an offset that moves the cursor to the end of that matched text- The search register (
@/) still stores the same pattern, sonandNcontinue 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
/bto land at the beginning explicitly when mixing offsets in complex workflows - Offsets compose with normal search, so you can still rely on
n/Nafter the first jump - Pair this with
:set hlsearchto keep full match visibility while landing exactly where edits should start