78

When using VIM's incremental search option I usually search and after I got to the first result (it will be highlighted) I use the / key to jump to the next result.

But:

  1. For this I need to 'cancel' my search and go back to Normal Mode in order to jump the next result.
  2. Pressing / makes VIM jump to the next result but it won't highlight it.

I am wondering if there is a more efficient way to jump between the results using incremental search and get them highlighted.

zoltanctoth
  • 2,788
  • 5
  • 26
  • 32

3 Answers3

119

The customary key for jumping to the next search result is 'n'.

I'm not entirely sure what you mean about highlighting - all search results should be highlighted if hlsearch is set, and for me it makes no difference if I go to the next result with 'n' or with '/'.

Matthew Walton
  • 9,809
  • 3
  • 27
  • 36
  • 2
    Matthew, thanks. However, I do incremental search, type (it jumps and highlights) than I press ENTER than use 'n' and the cursor jumps to the next result. But it is not highlighted. Do you think it should act differently? – zoltanctoth Nov 08 '11 at 10:15
  • Mine just highlights all of them straight away - if there are multiple search results visible in the buffer at the same time, I can see they've all got yellow backgrounds. This is the default configuration on my system, and IIRC is controlled by the 'hlsearch' setting. – Matthew Walton Nov 08 '11 at 10:29
  • 16
    And 'N' to search backwards. – sunsations Dec 10 '13 at 03:50
  • @MatthewWalton any idea, how i can jump a fixed number of results in search. I mean for example jump to the 10th matching line – GP cyborg Nov 11 '15 at 15:23
  • @GPcyborg Try `[number]n`? That should perform `n` `[number]` times, i.e. go forward `n` results. – Nic Jun 28 '19 at 15:32
14

With Ctrl-t and Ctrl-g you can move between matches without leaving the search mode

5

If you want to highlight all search hits you should set hlsearch not incsearch.

Benoit
  • 76,634
  • 23
  • 210
  • 236