34

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?

48

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.

  • Wow, that was way easier than I thought. :) Thanks! – Nathan Long Feb 8 '11 at 14:36
  • 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 8 '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 5:27
1

Is this more easier?

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

Searching REF

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.