`C-[` does not escape from insert mode in evil local mode

313 views Asked by At

I just started to use vim in my emacs. While most of the docs/wikis suggest turn on evil mode globally, I, being a emacs user at the first beginning, really prefer to keep evil mode local. That means, when I need model editing I will turn on the evil mode in that local buffer. I wrote a piece of elisp to toggle on/off evil mode for this purpose:

(defun toggle-evil-local-mode ()
"Toggle on and off evil mode in local buffer."
(interactive)
(if evil-local-mode
    (turn-off-evil-mode)
  (turn-on-evil-mode)))

(global-set-key (kbd "s-e") 'toggle-evil-local-mode)

However, there is one thing bothers me. I can not use C-[ to escape from insert or visual mode to normal mode (emacs reads the keystroke as ESC- and waiting for more input in the echo area ), Esc key works fine though. But if I turn on the evil mode globally, C-[ just work the same as Esc key.

You might notice that I am using a Mac from the keybinding. While I can use Esc key currently, but what if I upgrade to a new MBP with those evil touch bar in the future? So is there any way to fix this problem? Any suggestion will be appreciated.

1

There are 1 answers

1
Gordon Gustafson On BEST ANSWER

Looks like a bug in Evil. Let me know if this works:

(defun turn-on-evil-mode-fixed-escape ()
  "Turn on Evil in the current buffer AND `evil-esc-mode'. This makes C-[ work
like <escape> when using `evil-local-mode'."
  (interactive)
  (turn-on-evil-mode)
  (evil-esc-mode 1))