15

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?

user229044
  • 232,980
  • 40
  • 330
  • 338
Troydm
  • 2,642
  • 3
  • 24
  • 35

4 Answers4

12

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.

vmpstr
  • 5,051
  • 2
  • 25
  • 25
8

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

blueyed
  • 27,102
  • 4
  • 75
  • 71
Troydm
  • 2,642
  • 3
  • 24
  • 35
  • since i can't accept my answer i'll accept vmpstr which is basicly explanation of the same technique used in this cmap combo – Troydm Feb 08 '12 at 15:12
  • I've improved this a bit (using `cnoremap` and ``, because I have mapped / for completion already): `:cnoremap n/`. Unfortunately this attempt adds entries to the jumplist for each step, which the intermediate steps before `` in `incsearch mode` do not so. – blueyed Sep 13 '14 at 23:10
3

I have incsearch and hlsearch enabled. So I hit / to enter search mode. Then I type text which I want to search for and it finds the first occurrence.

Okey so far ...

Here, I can't quite understand what you're asking.

Then I want to jump to next occurrence of the text I typed without exiting search mode

This is done by pressing n

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.

You got me lost here ... isn't this behaviour exactly what incsearch enables you?

Rook
  • 60,248
  • 49
  • 165
  • 242
  • In incsearch mode, as you search it will go to the location of the next match, what he wishes to do is without having to press enter & press 'n', find some way to jump to that next match without ever leaving the search mode. – Dhruva Sagar Feb 08 '12 at 15:03
  • @DhruvaSagar - I think I understand; more emacs behaviour, so to speak. – Rook Feb 08 '12 at 16:00
  • @Idigas well I don't know about that, but I don't think it's really possible to achieve what he wants... – Dhruva Sagar Feb 08 '12 at 16:05
0

Use Ctrl-g or Ctrl-t for incremental search. When you want to search something hit /some, then hit Ctrl-t this will jump the cursor to first some, but you stay in search mode, you can add "thing" to search, and search pattern will be /something.