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*.
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.
You can do this with Helm
by entering a partial major-mode name prefixed with
*. For example:
*sh etc. You can also use negation, e.g.
to narrow down all non-Org mode buffers, or specify multiple
major modes, e.g.
M-a to mark those buffers and
M-D to kill them.
For example, to kill all dired buffers:
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
And with Icicles you can act on all matching candidates at once, with
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
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.