Issue #69 invalid

Delay between Esc (or C-[) and modeswitch

Anonymous created an issue


I seem to have the opposite problem as the person in issue #65. When in terminal mode, hitting Esc (or C-[) then immediately hitting another key sequence (like : or dd) results in the Esc being used as a modifier instead of a mode-switch followed by further keysequences. evil-esc-delay is indeed 0 by default. setting it to .01 made it worse (as I expected). is there anyway to have Esc (or C-[) be bound in such a way so there is never a delay and the modeswitch is always immediate? this problem is keeping me trapped in GUI emacs because I code too fast to wait the 1-2 seconds for the modeswitch to actually occur. Aside from this I was hugely enjoying evil in emacs -nw.

Comments (8)

  1. Frank Fischer repo owner

    (Reply via

    I noticed something like this, too, but it only happened inside a tmux or screen session. In a plain terminal (e.g., xterm) the ESC key worked perfectly. Obviously in this case it's the terminal emulator that delays the ESC key (btw, the same delay could be noticed when using VIM inside the tmux). So please tell us which terminal emulator, OS, Emacs version and so on you are using. And please try the same in a plain terminal (xterm, linux console).

    For your other question: I'm not aware of a way the get an immediate mode switch, at least not using the ESC key. If one would bind ESC directly to, say, 'evil-normal-state, then no M-<key> or C-M-<key> key sequence would work anymore, and this is certainly not acceptable.

  2. Anonymous


    Thanks for the hint: didn't even think to blame tmux. that was totally it. running emacs -nw straight in gnome-terminal caused Esc to behave as normal. At this point, do you have any suggestion? sounds like I should poke around at my tmux config to see if I can prevent the delay there.

    For the record, i'm using Ubuntu 11.04 with tmux in gnome-terminal running emacs23.

    Interestingly, I've for the past year used vim in tmux for all my coding (and before that, vim in screen) and have never seen such behavior.

    Thanks for such a neat package :) I would've never tried emacs without it.

  3. Anonymous

    It doesn't make any sense to me at all, but

    set -s escape-time 0

    seems to fix the problem. It doesn't make sense because the documentation says escape-time is how long tmux pauses after your control key (like C-b or, for me, C-a) to see if you're hitting an escape sequence. Seems to affect the Esc key itself, though.

    Clearly my monkeying with evil-esc-delay having an effect either way was my imagination.

    Thanks again, I'll switch to -nw for today and confirm that this it working isn't just my imagination once again.


  4. Frank Fischer repo owner

    The tmux manual states

    escape-time time
                         Set the time in milliseconds for which tmux waits after
                         an escape is input to determine if it is part of a
                         function or meta key sequences.  The default is 500

    The problem are meta-key-sequences, i.e., anything with M-<key>. And this is exactly the problem I described several times on the list or in other issues. In terminals M-<key> is encoded as ESC <key>, i.e., as a sequence of two or more characters, the first one being ESC.

  5. William Forsyth

    I had the same delay problem.
    My fix was to install key-chord.el and bind jj to evil-normal-state see this stack overflow. Binding to something other than esc eliminates the timing issues with interpreting the esc command. Here is the line i added to my .emacs:

    (require 'key-chord)
    (key-chord-mode 1)
    ;;bind the escape to jj
    (key-chord-define evil-insert-state-map "jj" 'evil-normal-state)
    ;;and while we're at it bind jk to the indispensable insert-normal mode (ctrl-o)
    (key-chord-define evil-insert-state-map "jk" 'evil-execute-in-normal-state)

    Switching to normal mode is now instantaneous, as well as easier since jj is way more ergonomic than finding esc or ctrl-[.

  6. Log in to comment