reddit / emacs

Make :q or :wq not killl emacs in evil mode

LowCom · 2022-05-24 06:17
If there is no unmodified buffer, trying to exit current buffer or window through :q or :w kills emacs, which is super annoying. This makes it very hard to work with read only buffers. I guess one alternative is to use :bd which deletes current buffer which is what I actually want to do. How do I make it do exactly as what vim does?
alebrick · 2022-05-24 08:46
It may not solve everything you want (I forgot what Vim's behavior was here), but you can make yourself less likely to close Emacs accidentally by adding this to your init.el: (setq confirm-kill-emacs #'yes-or-no-p) Then you'll get prompted before Emacs is killed. It's been a lifesaver for me.
sco_t · 2022-05-24 09:47
For making :wq save and close the current buffer, I've got: (evil-ex-define-cmd "wq" 'save-and-kill-this-buffer) (defun save-and-kill-this-buffer()(interactive)(save-buffer)(kill-current-buffer)) I use :q for quitting everything and :bd for the rare case where I want to close a buffer without saving but you should be able to evil-ex-define-cmd :q to kill-current-buffer if you wanted. Edit: Actually redefining :q like that would make it hard to actually quit once you actually are done with all buffers. I think that's why I left it. Could probably do a fancy check to see what buffers exist and quit if only non-interesting ones but I guess just blocking wq from killing everything was good enough for me.
klikklakvege · 2022-05-24 10:03
I had a couple of minor issues with evil like this that were solved by switching to viper. Strange that everybody is using evil and viper is never mentioned.