1

How can I make :q in spacemacs' evil mode, kill the buffer and delete the window, but not kill Emacs?

Coming from VI, the habit of closing with :q/:wq or ZZ/ZQ doesn't translate very well into Emacs.

I'm too new to figure out how to reprogram this.

I've come to really like Spacemacs, but need help in modifying this behavior.

2
  • As far as I know, in vim, :q quits vim. To delete a buffer and window you should use :bd (I might be wrong, but this is how I remember it). Anyway, these things work similar in Spacemacs. However, for me (and I guess for most SPACEmacs users) the preferred way to achieve this is by pressing SPC b x (or equivalently SPC w x, but I think SPC b x is slightly more convenient to type). Jun 30, 2022 at 14:32
  • I agree with what you're saying, however as I'm learning to 'live' in Emacs through Spacemacs and evil-mode, I'm trying to do away with the 'muscle memory' I have from vim. As a terminal editor, quitting to go back to the terminal is 'natural' (at least for me), with Emacs, I want to prevent myself from my old habits. So while what I'm asking is not best-practices, it's a way for me to learn more about how everything works/inter-connects.
    – Lockszmith
    Jun 30, 2022 at 16:03

1 Answer 1

1

The commands entered by pressing : are, similar to vim, called 'evil-ex-commands'. How to remap them is described in this issue. For your case, you probably want:

(global-set-key [remap evil-quit] 'kill-buffer-and-window)

You could add this line to your dotspacemacs/user-config.

In the issue, it is also described that the evil-ex bindings are defined in the evil-ex-commands variable. Another way to find the binding is via SPC h d x (then q, for this case).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.