VIM, incremental search: How can I jump to the next result and get it highlighted?
Asked Answered
J

3

79

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.

Judgemade answered 8/11, 2011 at 10:8 Comment(0)
B
120

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 '/'.

Bornie answered 8/11, 2011 at 10:12 Comment(5)
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?Judgemade
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.Bornie
And 'N' to search backwards.Perlaperle
@MatthewWalton any idea, how i can jump a fixed number of results in search. I mean for example jump to the 10th matching lineBeginning
@GPcyborg Try [number]n? That should perform n [number] times, i.e. go forward n results.Jinni
S
17

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

Sepaloid answered 21/3, 2021 at 18:24 Comment(2)
This is what I was looking for. I wanted to have the currently selected match to be highlighted.Tripterous
For me this is the answer to the questionPeroneus
M
5

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

Majesty answered 8/11, 2011 at 10:18 Comment(3)
That was the problem. Thanks.Judgemade
@zoltanctoth: you should really accept the other answer instead, because he was first and told the same actually.Majesty
You are right. I have missed the hlsearch part in @matthew's answer. Thanks for noticing.Judgemade

© 2022 - 2024 — McMap. All rights reserved.