0

I have been using Emacs for a while and recently started using evil mode. I exclusively use emacs-nox (command line emacs).

The only thing that's missing for me is C-z to pause emacs and bring me back to my bash shell.

For some reason when evil mode is enabled, the C-z hotkey does nothing. When I disable evil mode, C-z works just fine. I have never used vi/m before, so I'm not sure if there is a vi/m specific command to pause (I'm pretty C-z in vi will pause it as well). I understand that C-z is a bash command, not an Emacs hotkey. I'm not sure why it is interrupted by evil mode.

Drew
  • 75,699
  • 9
  • 109
  • 225
marc.soda
  • 123
  • 5

2 Answers2

1

I'm not sure why it is interrupted by evil mode.

It's interrupted by evil mode to switch into the "emacs" state, a mode where evil falls back into your regular Emacs keybindings:

(describe-key "\C-z")

C-z runs the command evil-emacs-state (found in evil-motion-state-map), which is an interactive compiled Lisp function in ‘evil-states.el’.

It is bound to C-z.

(evil-emacs-state &optional ARG)

Enable Emacs state. Disable with negative ARG. If ARG is nil, don’t display a message in the echo area.

However, suspend-frame is also bound to C-x C-z, see (describe-function 'suspend-frame). This keybinding is not changed by evil mode.

Zeta
  • 1,045
  • 9
  • 18
  • Thank you very much for the response. It was super helpful. I never use `evil-emacs-state`. What would be the best way for me to remap `C-z` to `suspend-frame` in all states? – marc.soda Nov 19 '20 at 21:41
  • Update: to override this keybinding add `(define-key evil-motion-state-map (kbd "C-z") 'suspend-frame)` to your emacs init file. Thanks again @Zeta! – marc.soda Nov 19 '20 at 21:54
0

@Zeta's answer/comment helped me come up with this solution (copied from this duplicate question):

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).

wfsch
  • 1