10

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?

Mahmoud Al-Qudsi
  • 296
  • 1
  • 10

2 Answers2

5

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.

Mass
  • 14,080
  • 1
  • 22
  • 47
  • That might indeed be it. And since I never use to abandon the command line (ctrl+c only), this would probably fit the bill! – Mahmoud Al-Qudsi Sep 19 '17 at 02:29
  • Oof, this is good answer but, by god, is it some bad UI design! That's a serious betrayal of how works in pretty much every single program. It's even in the name of the damn key - "escape"! – iono Sep 26 '19 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 Sep 26 '19 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 Feb 03 '21 at 06:49
1

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

https://github.com/haya14busa/incsearch.vim

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

laktak
  • 2,933
  • 13
  • 27