56

In Vim, I know that / will search forward from the cursor, with n and N repeating the search forward and backward, respectively.

I also know that ? will search backward from the cursor, with n and N repeating the search backward and forward, respectively.

My question is, if I've done a ? search, and I want to re-run that as a / search (so I don't have to keep holding shift to move forward), is there a way to switch the previous search's direction without retyping the search term?

Nathan Long
  • 26,565

2 Answers2

80

Simply typing a ? without any text following it will re-run the search backwards.

I.e. typing / Return or ? Return will always rerun the last search, but in the direction you want.

k0pernikus
  • 2,158
Wes Hardaker
  • 2,636
  • 1
    Wow, that was way easier than I thought. :) Thanks! – Nathan Long Feb 08 '11 at 14:36
  • 1
    Hmmm, and apparently, ? or / followed by the up key cycles through a common history for the two. I thought each had their own history. – Nathan Long Feb 08 '11 at 14:40
  • Just a minor thing (looks pretty obvious), but I did miss it. You have to navigate to end of the file (ctrl + end) to reverse search it. – dimuthu Oct 24 '17 at 05:27
2

Is this more easier?

ctrl-o, ctrl-i - go through jump locations

Searching REF

Joshua
  • 141