How do I keep each search match centered and unfolded as I jump with n?
Answer
nzzzv
Explanation
When you are stepping through many matches, plain n often lands with poor context and can hide the match inside a closed fold. Chaining nzzzv solves both issues in one repeatable keystroke: jump to the next hit, recenter the viewport, and open folds just enough to reveal the line. This is especially effective during code review, refactors, or log triage where you repeatedly inspect nearby context.
How it works
njumps to the next match for the current/patternzzrecenters the cursor line in the windowzvopens folds at the cursor position so the match is visible
Because this is a normal-mode sequence, it is easy to map to a key you already use for search navigation.
Example
1 function render() {
2 if (featureFlag) {
3 // ... many folded lines ...
4 renderWidget();
5 }
6 }
Search for render. With folds enabled, n may land on hidden lines. nzzzv lands on each result, centers it, and opens the fold containing that result so you can immediately inspect surrounding code.
Tips
- Use the reverse variant
Nzzzvfor backward traversal - Works well with
:set hlsearchbecause the next hit remains obvious - If you rely on this heavily, map
nandNto includezzzvin your config