How do I position the cursor at a specific character offset from a search match?
Answer
/pattern/e+2
Explanation
Vim's search command supports an offset suffix that controls where the cursor lands after a match. The syntax /{pattern}/{offset} lets you position the cursor relative to the start or end of the match — useful when you need to land at a precise insertion point without manually navigating after the search.
How it works
The offset is appended after the pattern, separated by /:
/e— cursor lands at the end of the match/e+N— N characters past the end of the match/e-N— N characters before the end of the match/s+Nor/b+N— N characters after the start of the match/s-Nor/b-N— N characters before the start of the match/+N— N lines below the match line/-N— N lines above the match line
Example
Given this line:
const result = computeValue();
/computeValue/e+1<CR>— lands cursor on((1 char past end of "computeValue")/computeValue/s-1<CR>— lands cursor on space before "computeValue"/computeValue/e-4<CR>— lands cursor onV(4 chars before end)
Tips
- Offsets persist: press
norNto repeat the search and land at the same offset each time - Combine with operators:
c/result/e+1<CR>changes from cursor to just past the end of "result" - The same offset syntax works in Ex address ranges:
:/foo/e,/bar/s-1 deletedeletes precisely between two patterns - Use
/ewithout a number to jump to the last character of a match — handy forci"style edits where you need to start just inside a delimiter