Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
up vote 10 down vote accepted

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.

share|improve this answer
'kill-this-buffer is part of emacs and that should be used instead. – Jaseem Feb 26 '15 at 19:02

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)
share|improve this answer

I use this

(global-set-key (kbd "C-x k") (lambda ()
                              (kill-buffer (buffer-name))))
share|improve this answer
Minor improvement: (kill-buffer (current-buffer)) – Jaseem Feb 26 '15 at 19:01

Four years later in this thread I would recommend not binding kill-this-buffer to C-x k, at least on Windows and Emacs 24.5.1.

I had this binding for many years while moving .emacs from machine to machine, but on my Windows 8.1 this command suddenly began working weirdly. Sometimes it just did nothing and I had to close the buffer in some other way. I see from the source and bug 8184 this function is quite "smart" while it tries to detect that there is no "interesting" buffer to switch to and in this case prevent the user to close the buffer.

The code from the last answer above (from kindahero) seems better.

share|improve this answer

You must log in to answer this question.

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