How to Kill buffer in emacs without answering confirmation?

Viewed 8756

How to kill the buffer in emacs without being questioned.

5 Answers

Use (kill-current-buffer) instead of (kill-this-buffer) if you want to bind it to some key. See the docs for (kill-this-buffer)

...

This command can be reliably invoked only from the menu bar, otherwise it could decide to silently do nothing.

and (kill-current-buffer)

...

This is like ‘kill-this-buffer’, but it doesn’t have to be invoked via the menu bar, and pays no attention to the menu-bar’s frame.

So I would put the following in my init.el:

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

This works at least in emacs 26.1.

Related