Unpredictable VI mode behavior on prompt return
I’ve been having some difficulties with VI mode exiting insert mode, seemingly at random, after the prompt returns. Worse, it takes about half a second for it to happen, so my inputs are often dropped. I’m sure there’s some logic to it, but I haven’t been able to isolate what causes the behavior.
Can anyone help me understand what might cause ZSH to switch to Normal mode without the escape key being pressed? Is there a non-hack-ish way to make the mode for the next prompt more consistent?
Edit: I use the Starship prompt.
Posted Dec 13, 2021, 4:59 PM UTC
16
What do you mean by "after the prompt returns"?
With the default bindings, the current keymap changes from vicmd (a.k.a. vi command mode, a.k.a. vi normal mode) to viins (a.k.a. vi insert mode) when you press
i,RETURNorENTER.If it changes for you when you press some other key, this is most likely caused by your configuration files.
I mean when the next prompt is displayed after a program terminates, after pressing
^(C,)^C, etc.Do you have a
zle-line-inithook defined? I.e. what doeswhich zle-line-initoutput. Also check forzle-keymap-selectandzle-line-pre-redrawhooks. Have you got any setup to display vi mode in the prompt because a bug in that is a likely culprit.Can you elaborate on what you mean by "after pressing
C,". Is the comma part of your key press? Did you actually meanCtrl-C. I'm puzzled by Reddit's rendering of your C in superscript.Also what is the value of
$KEYTIMEOUT. The default of20can be somewhat too high on modern systems which has caused recommendations of0to circulate but0is really quite a bad idea.5may be a better choice. Many other keys generate a sequence that starts with an escape and could be being interpreted as an actual escape key press.Indeed, I did mean
^C. Now I know that Reddit enables superscript with^.I think you're onto something with the "setup to display vi mode in the prompt" note. I definitely do have something in place for that, which I'll take a look at shortly. I'll look for
zle-line-init, et. al., as well.Thanks!
Edit: Also, here's my vi-mode config: https://github.com/bgshacklett/dotzsh/blob/master/conf.d/00-vi-mode.zsh
I see that I'm pulling in a plug-in there. I'm going to see if an update helps, or if there are any known issues, there.
The
zle-line-initpart of that plugin does:To be sure I'd need to read through the whole plugin but at a guess, what it is trying to do is select normal mode if you were in normal mode for the previous command-line. That might explain why it appears to only happen randomly.
Does it help if, after setting up the plugin, you do: