20

I'm wondering how it can be done, so Emacs doesn't pop the prompt asking me whether I really want to kill current buffer with C-x k shortcut.

Interesting thing is that same action done via toolbar kills buffer instantly without prompting the user. Any solution? Thank you.

4 Answers 4

22

By default, Emacs doesn't ask you if you want to kill the buffer. It does ask you which buffer you want to kill.

If you don't want to be asked which buffer you want to kill, you can use this:

(global-set-key (kbd "C-x k") 'kill-this-buffer)

If you're being prompted for confirmation, then there's something in your .emacs (or the site specific initialziation). Try running emacs -q to check Emacs w/out your .emacs.

Note: Verified with Emacs 23.2.

2
11

You can find out what that menu entry does with C-h k and then clicking on the entry. It turns out to be a command named kill-this-buffer.

Then you can bind that command to a key combination:

(global-set-key "\C-xk" 'kill-this-buffer)
1
  • This does not work anymore: debbugs.gnu.org/db/71/71510.html Commented Jun 23 at 16:03
2

I use this

(global-set-key (kbd "C-x k") (lambda ()
                              (interactive)
                              (kill-buffer (buffer-name))))
2
  • Minor improvement: (kill-buffer (current-buffer))
    – Jaseem
    Commented Feb 26, 2015 at 19:01
  • Since c. Emacs 24.3 you can just (global-set-key "\C-xk" 'kill-this-buffer)
    – RichieHH
    Commented Jan 2, 2020 at 10:36
0

answered here: https://stackoverflow.com/questions/6467002/how-to-kill-buffer-in-emacs-without-answering-confirmation

(defun volatile-kill-buffer ()
   "Kill current buffer unconditionally."
   (interactive)
   (let ((buffer-modified-p nil))
     (kill-buffer (current-buffer))))

(global-set-key (kbd "C-x k") 'volatile-kill-buffer)     ;; Unconditionally kill unmodified buffers.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .