Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vim incremental search next result

I have incsearch and hlsearch enabled

So I hit / to enter search mode.

Then I type text I want to search for and it finds the first occurrence of the text I typed.

Then I want to jump to next occurrence of the text I typed without exiting search mode so that I could refine my search text later without having to exit to normal mode, then hitting n and then going back to search mode by hitting / again.

If this is possible, how can I do it?

like image 999
Troydm Avatar asked Feb 08 '12 14:02

Troydm


People also ask

How do I cycle through a search in Vim?

Press Esc to cancel or press Enter to perform the search. Then press n to search forwards for the next occurrence, or N to search backwards. Type ggn to jump to the first match, or GN to jump to the last.

What is Incsearch Vim?

incsearch. vim is a Vim plugin which improve incremental searching. It provides functionality to highlight all matches while searching, to move cursor to next/previous match while searching and so on.


2 Answers

The best thing that I can find that you can do is the following:

Search for your pattern using /blah

Then, hit n or ? until you see what's out there...

Then go back to / and press CTRL-r /

this will bring back the last pattern that you searched for, so you can continue entering more text there...

I'm sure you can remap that combination to some key so that you can quickly go back to the search with the pattern already entered.

like image 164
vmpstr Avatar answered Oct 18 '22 00:10

vmpstr


I've found a way thanks to bwana147 from #vim irc channel on freenode.net

:cnoremap <c-n> <CR>n/<c-p>

After that typing text in search mode and then hitting ctrl-n goes to next occurrence of that text without exiting search mode

like image 40
Troydm Avatar answered Oct 18 '22 01:10

Troydm