5
votes

In Emacs evil mode, the key combo C-z is to toggle evil mode. I would like to rebind it to escape to shell instead. How would I do this ?

I have read about eshell, it seems to be great, but for now I would like to work with my zsh shell first.

Multi term seems to designed for this job, but I think escaping to shell is fine for me, since I'm used to this flow in Vim.

Thanks for reading.

3

3 Answers

4
votes

Perhaps what you need is C-x C-z.

3
votes

Just have the same requirement, and here's my configurations:

(add-to-list 'load-path "~/.emacs.d/evil")
(add-to-list 'load-path "~/.emacs.d/evil/lib")
(setq evil-toggle-key ""); remove default evil-toggle-key C-z, manually setup later
(require 'evil)
(evil-mode 1)

;; remove all keybindings from insert-state keymap, use emacs-state when editing
(setcdr evil-insert-state-map nil)

;; ESC to switch back normal-state
(define-key evil-insert-state-map [escape] 'evil-normal-state)

Ref: 1. https://gist.github.com/kidd/1828878
2. https://askubuntu.com/questions/99160/how-to-remap-emacs-evil-mode-toggle-key-from-ctrl-z

0
votes

C-x C-z will suspend the frame and return you to the shell.

C-z as you mention toggles evil mode on/off.

I swap their behavior in evil like so:

(define-key evil-motion-state-map (kbd "C-z") 'suspend-frame)
(define-key evil-emacs-state-map (kbd "C-z") 'suspend-frame)
(define-key evil-motion-state-map (kbd "C-x C-z") 'evil-emacs-state)
(define-key evil-emacs-state-map (kbd "C-x C-z") 'evil-exit-emacs-state)

See this commit for an example (where I also make C-z emulate vim-behavior in insert/replace mode).