Don’t kill-buffer, kill-this-buffer instead

Here’s a tiny tip. By default C-x k runs the command kill-buffer which prompts you for which buffer you want to kill, defaulting to the current active buffer. I don’t know about you, but I rarely want to kill a different buffer than the one I am looking at, so I rebind C-x k to kill-this-buffer which just kills the current buffer without prompting (unless there are unsaved changes).

Just add this to your emacs config file

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

    Nice Tip. Man.

  • simple, however super effective.

  • thanks!

  • Did you know that it is bound by default to Super-k?

    • Bart

      No it’s not.

      • Oh yes it is. Start a fresh emacs (emacs -q) then `C-h k` then `Super-k` and you’ll see this doc:

        s-k runs the command kill-this-buffer (found in global-map), which is an interactive compiled Lisp function in ‘menu-bar.el’.

        It is bound to s-k, s-&, .

        (kill-this-buffer)

        Kill the current buffer.

        When called in the minibuffer, get out of the minibuffer

        using ‘abort-recursive-edit’.

  • This is the kind of thing that is clearly better, but muscle memory might stop this from ever helping me. I’m going to try it out, but I’m expecting that for at least a month or two, I’m going to keep finding myself in a random directory after killing a buffer and instinctively hitting RET