Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

With EditMode::Vi, insert mode should not have keyseq_timeout applied when receiving KeyPress::Esc #416

Closed
bobbygebert opened this issue Jul 13, 2020 · 11 comments

Comments

@bobbygebert
Copy link

When in insert mode, you have to wait for 500ms (or whatever timeout was given in the editor config). I would expect hitting the escape key to return to command mode immediately.

@gwenn
Copy link
Collaborator

gwenn commented Jul 14, 2020

See #371

In vi mode, when you read an ESC from stdin, you don't know if it is a single escape or an escape sequence

@homburg
Copy link
Contributor

homburg commented Jul 30, 2020

@gwenn Maybe we could change the default value for vi mode timeout? There is not delay in zsh/bash vi mode.

@homburg
Copy link
Contributor

homburg commented Jul 31, 2020

No, you are absolutely right.

Tested some different delays for switching from insert mode to command mode with escape:

environment shell delay reference
macOS bash ~0ms ?
ubuntu (docker) bash 500ms ...
macOS zsh 400ms https://github.com/zsh-users/zsh/blob/b74635aa741d7e2d8d81f601f0192e79037aa991/Src/params.c#L823
alpine (docker) ash ~100ms ?
* fish shell 30ms fish-shell/fish-shell#6590 :-)

An important distinction is that bash seems to recognize command movement keys immediately after escape, eg:

  1. <insert mode>
  2. input: Esc, h
  3. (without delay) <command mode>, caret one step left

Not sure how that's implemented

@bobbygebert
Copy link
Author

bobbygebert commented Aug 4, 2020

Yeah @homburg, the fact that movement keys aren't recognized after escape is what surprised me. Maybe that is the solution. We could add key sequence rules for those combinations pretty easily, right?

@homburg
Copy link
Contributor

homburg commented Aug 5, 2020

@bobbygebert Sounds like a good strategy, what do you think @gwenn ?

For reference, I think this is relevant bash readline logic: https://git.savannah.gnu.org/cgit/readline.git/tree/readline.c#n901 but I'm not familiar enough with the code to understand it.

@gwenn
Copy link
Collaborator

gwenn commented Aug 5, 2020

I am not sure to understand:

the fact that movement keys aren't recognized after escape is what surprised me.

Does it mean that movement keys are not recognized when timeout is too low ?
Or does it mean that movement keys are not recognized even when timeout is high ?

@homburg
Copy link
Contributor

homburg commented Aug 5, 2020

@gwenn it means that bash recognizes the movement keys, eg. j as <command-mode> keys during the timeout, ie. esc, j -> instant <command mode>

@homburg
Copy link
Contributor

homburg commented Aug 5, 2020

@gwenn I did a quick proof-of-concept, that seems to match the behavior: #426

@gwenn
Copy link
Collaborator

gwenn commented Aug 6, 2020

@homburg Ok, I understand now. We don't expect Meta-X in Vi mode only escape sequence. So Meta-X means Esc (exit insert mode) and do command associated to X. Looks good to me. We should be able to refactor/split vi_command method and call the bottom part from your patched block in vi_insert.
Thanks.

@gwenn
Copy link
Collaborator

gwenn commented Sep 13, 2020

6.3.0 released

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants