Emacs - kill buffer without prompt

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.


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)

I use this

(global-set-key (kbd "C-x k") (lambda ()
                              (interactive)
                              (kill-buffer (buffer-name))))

Tags:

Emacs