5

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?

  • 2
    If you use enter instead of esc it should work out of the box. – Christian Brabandt Jul 20 '17 at 22:44
  • @ChristianBrabandt like I said, I've tried teaching myself to do that. Muscle memory. – Mahmoud Al-Qudsi Jul 20 '17 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 Sep 26 at 11:22
3

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! – Mahmoud Al-Qudsi Sep 19 '17 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 Sep 26 at 11:20
  • @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 at 19:22
0

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).

  • I already use it :( – Mahmoud Al-Qudsi Jul 20 '17 at 22:45
  • Why don't you open an issue or PR? – laktak Jul 21 '17 at 10:28

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.