How do I move through search matches while still typing the pattern?
Answer
<C-g> and <C-t>
Explanation
While the search prompt is open (with incsearch enabled), pressing <C-g> advances the cursor to the next match and <C-t> moves it to the previous match — all without leaving the search prompt. This lets you visually explore matches and refine your pattern before committing.
How it works
<C-g>— jump to the next occurrence of the current pattern (mnemonic: Go forward)<C-t>— jump to the previous occurrence (mnemonic: go back, like Tab order)- Both work only while
:set incsearchis active (the default in Neovim and Vim 8+) - Press
<CR>to confirm the search and land on the current match, or<Esc>to cancel
Example
Suppose you have a file with many references to config and you want to land on the third one:
/config
Instead of pressing <CR> and then nn, you stay in the search prompt and press <C-g> twice to move to the third match, then confirm with <CR>. The cursor ends up exactly where you want.
Tips
- Combine with
<C-l>to extend the search pattern one character at a time from the current match, narrowing down results interactively - The match count displayed in the status line updates in real time (in Neovim with
showcmdenabled) - Useful when you want to distinguish between
getUserandgetUserById— type enough of the pattern, navigate to the right instance, then commit