Given the document


(where ^ denotes the cursor position), the forward search /a\? succeeds, but the backward search ?a\? fails. Why?


This is documented:

\?      Just like \=.  Cannot be used when searching backwards with the "?"
        command. {not in Vi}

Note that \? is "Just like \=", so you can



  • 1
    Thank you! I only read the line /\? \? \? 0 or 1 as many as possible (*) in the documentation for /multi; it didn't occur to me that I had to dive further into the documentation. I had also wondered why there was a synonym available …. – LSpice Jan 4 '17 at 23:08

From :help /\?:

\?      Just like \=.  Cannot be used when searching backwards with the "?"
        command. {not in Vi}

It's confusing behaviour, but the reason for this is that you can use the command with an offset to go n lines up or down after the match:


There is no easy way to disambiguate between regular ?s and the ? to separate the pattern from the offset. This is why \? behaves as a literal ?, and not as the special atom you expect it to.

  • Thank you! I have accepted nobe4's answer because it was slightly earlier, but I appreciate your explanation. Do you know why escaping the ? isn't enough to disambiguate? – LSpice Jan 4 '17 at 23:08
  • 1
    @LSpice That's okay. Fastest gun in the West and all. Anyway, how would you escape ?? There are three possible meanings of ?: literal ?, \?, and offset separator. In principle Vim could make a new atom for this (such as \\? or \??) but this would cause more compatibility problems and confusion than it solves, and since it's already identical to the existing \= I don't really see why this should be added. – Martin Tournoij Jan 4 '17 at 23:17

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.