For years I unknowingly used some, shall we say, deviant distribution of vim that would stay at the location of the highlighted search result after hitting <Esc> in the middle of a search instead of jumping back to the original position.

I've tried for more than a year now to forget that muscle memory, but I cannot for the life of me stop pressing <Esc> once what I've typed in the search has taken me to the position I'm searching for.

Does anyone know a) how I can get that behavior back, b) what *nix distribution had a copy of vim that defaulted to this behavior?

  • 4
    If you use enter instead of esc it should work out of the box. Commented Jul 20, 2017 at 22:44
  • @ChristianBrabandt like I said, I've tried teaching myself to do that. Muscle memory. Commented Jul 20, 2017 at 22:45
  • This should just be the default behaviour (like it is in most modern editors). Vim has a selection history – that's the perfect system to use to go back to your previous selection after searching.
    – iono
    Commented Sep 26, 2019 at 11:22

2 Answers 2


There is an option for this: set cpoptions+=x

From :help cpo-x

    x   <Esc> on the command-line executes the command-line.
        The default in Vim is to abandon the command-line,
        because <Esc> normally aborts a command.  |c_<Esc>|

It is also the default vim behavior when compatible is set, and is the behavior of vi in distributions that ship the "real thing," such as Arch Linux.

  • That might indeed be it. And since I never use <ESC> to abandon the command line (ctrl+c only), this would probably fit the bill! Commented Sep 19, 2017 at 2:29
  • Oof, this is good answer but, by god, is it some bad UI design! That's a serious betrayal of how <Esc> works in pretty much every single program. It's even in the name of the damn key - "escape"!
    – iono
    Commented Sep 26, 2019 at 11:20
  • 1
    @iono, worth pointing out <esc> is also how you leave insert mode, i.e. "commit" the text edit, so by that it isn't too surprising
    – Mass
    Commented Sep 26, 2019 at 19:22
  • @Mass thanks, that's interesting to learn! I was assuming Vim was writing to the buffer with every change in insert mode. I've just been hitting <esc>z, which is handy anyway as it preserves the "mistake" in the edit timeline just in case it wasn't actually a mistake.
    – iono
    Commented Feb 3, 2021 at 6:49

I don't think you can configure this in VIM (see help incsearch) but


may be an option (if it's not already included you could ask for or implement that feature).

  • I already use it :( Commented Jul 20, 2017 at 22:45
  • Why don't you open an issue or PR?
    – laktak
    Commented Jul 21, 2017 at 10:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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