0

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.

Fanpeng
  • 332
  • 1
  • 9

1 Answers1

2

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))
Gordon Gustafson
  • 40,133
  • 25
  • 115
  • 157
  • @Daniel Sure thing! If it solved your problem, can you click the checkmark to left? That will mark the question as 'resolved' when it's shown in various places on the site. – Gordon Gustafson Jan 03 '17 at 01:53