0

I am new to (Spac)Emacs with Evil, and I did quite some searching to find an answer to this question, so I hope this is a 'legitimate' question here.

Is there a default single command to write a buffer and kill only the buffer instead of quitting Emacs. I found answers for how to just quit a buffer here and here but I do not know how to do the same thing including saving the buffer in one command. For example, I can delete the buffer with :bd, but :wbd does not work.

If there is no default way, then what is a nice alternative to get this job done (in a single command of course).

  • Only after I asked this question I looked up how to actually get this done in emacs (not spacemacs). So I found a reasonable alternative to :wq (without killing emacs) using the key combination C-x C-s C-x k. But still a more spacemacs-like alternative would be nice too... – dalanicolai Nov 29 '19 at 16:15
  • Just a nitpick: your question (and comment/answer) is really about Evil rather than about Spacemacs. I've seen many people confuse the two. – Stefan Nov 29 '19 at 16:59
  • @Stefan I agree, thanks for pointing that out. I slightly edited the question to include its relation with evil. – dalanicolai Nov 30 '19 at 12:12
1

If there's no such command in Vim, there won't be one in Evil either. If there is one, but it doesn't work right, consider reporting a bug. :wbd isn't a thing in my Vim, but it's not hard to recreate it with a bit of Emacs Lisp:

(evil-define-command evil-write-and-kill-buffer (path)
  "Save and kill buffer."
  :repeat nil
  :move-point nil
  (interactive "<f>")
  (if (zerop (length path))
      (save-buffer)
    (write-file path))
  (kill-buffer (current-buffer)))

(evil-ex-define-cmd "wbd[elete]" 'evil-write-and-kill-buffer)
| improve this answer | |
  • I did not realize that I never used this in vim. I only worked half a year in vim and used to open multiple files in multiple windows (switching windows with alt+` in gnome is quite efficient too for simple projects). I checked now how this would work in (neo)vim and I found that the command :w|bd does the job. I tested this command in evil too but it writes a file named |bd so I will consider to file a bug then. Anyway, thanks for your great answer! I will accept it after I tested it but for now as I said I am new to (Spac)Emacs and Evil. @wasamasa – dalanicolai Dec 1 '19 at 11:11

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.