I know about kill-matching-buffers but that searches buffer names, I want instead to search buffer modes. For example, I might want to kill all buffers that have "notmuch-" or "[Notmuch]" as substrings in the mode column in the *Buffer List*.

  • Also I just found out that you can set message-kill-buffer-on-exit to t for great justice
    – Sandra
    Jul 3, 2020 at 13:09

3 Answers 3


You can use M-x ibuffer which I recommend binding to C-xC-b to replace the default (or whatever binding you prefer).

Use %m to mark buffers by matching a regexp against the displayed mode-name (e.g. Emacs-Lisp). Then use D to kill the marked buffers.

"notmuch-" or "[Notmuch]"

Note that, as we're dealing with regexps, you would need to enter \[Notmuch\] for the latter.

You could alternatively use *M to match a specific mode symbol (e.g. emacs-lisp-mode). You get completion for the possible values with this approach.

ibuffer is very powerful; be sure to use C-hm to learn about its grouping and filtering abilities, amongst other features.

  • Fantastic answer in more ways than one. I'm might keep the default *Buffer List* bound to C-x C-b since I usually keep my frames in a proportional front (I guess I could wrap Ibuffer in a function that toggles it to monospace for the duration, though) but I'm definitely going to me doing M-x ib RET whenever I want to fix this particular problem. Works perfectly♥
    – Sandra
    Jul 2, 2020 at 20:31
  • Also great that it didn't require installing any new packages, like Helm (which I've never heard of but it might be awesome) or Icicles (which I've used in the past and constantly struggled with and was so glad to get rid of—but if it does solve this particular problem then that's a feather in its cap, ofc♥)
    – Sandra
    Jul 2, 2020 at 20:39

You can do this with Helm by entering a partial major-mode name prefixed with *. For example: *lisp, *sh etc. You can also use negation, e.g. !*org to narrow down all non-Org mode buffers, or specify multiple major modes, e.g. *!lisp,!sh,!fun etc.

Then press M-a to mark those buffers and M-D to kill them. For example, to kill all dired buffers:

  1. M-x helm-buffer-list
  2. *dired
  3. M-a
  4. M-D

If you use Icicles then, with any command that completes against buffer names, you can filter (include or exclude) the candidates by mode (either exact mode match or derived-mode-p).

And with Icicles you can act on all matching candidates at once, with C-!.

If you use a plain prefix arg (C-u) with a command with buffer candidates then the candidates are only buffers with the same mode (or a mode derived from the same mode) as the current buffer.

So for example, if you use C-u C-x k then the only candidates for completion are buffers in the same mode as the buffer you're currently in. You can then use C-! to kill them all.

Or you can use C-x k (no prefix arg), and then hit a key to remove some candidates, then use C-! to kill all the remaining candidate buffers.

To remove buffer candidates that have a given mode, you can use C-x C-m -. You're prompted for the mode. Or to remove all candidates except those with a given mode (i.e., keep only buffers with that mode), use C-x C-m +. Again, once you've filtered out candidates, you can kill all remaining candidate buffers using C-!.

More generally, when you use any Icicles command that completes against buffer names, you can filter the candidates (by mode, as indicated above, or in other ways) and then use C-u S-delete to kill all remaining candidates. So you need not use C-x k - you can kill buffers even when you use C-x b or whatever. Obviously, since this is not the main purpose of a command such as C-x b, if you use S-delete you're asked to confirm killing.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.