How do I jump to the next search match and keep it centered on the screen?
Answer
nzz
Explanation
Typing nzz chains two normal-mode commands: n jumps to the next match of the last search, and zz immediately redraws the screen so the cursor line is vertically centered. This keeps the context visible on both sides of your match as you step through results — especially useful when searching through a long file and the matches would otherwise appear near the very top or bottom of the screen.
How it works
n— move cursor to the next match (forward, wrapping at end of file)zz— redraw with the cursor line at the vertical center of the window
The two-command sequence is instantaneous in practice, and Vim allows any normal-mode command to follow another without a separator.
Example
Searching for TODO in a 500-line file:
/TODO<CR> → jumps to match, which may appear at top or bottom of screen
nzz → jumps to next match AND centers it
Nzz → jumps backward to previous match AND centers it
Tips
-
You can permanently remap
nandNto always center results:nnoremap n nzz nnoremap N Nzz -
Add
zvtoo (open fold if match is hidden) to ensure the match is always visible:nnoremap n nzzzv nnoremap N Nzzzv -
Similarly,
*zzsearches for the word under the cursor and centers it immediately.