Sometimes, when work is finished on one github/issues, its helpful to "reset" the list of opened files. So far I've been doing M-x kill-emacs and then restart, but that's a bit heavy handed.

I tried this tip , that did kill actual file buffers. I want to to be able to reset things so that this kind of "miscellaneous" buffers aren't laying around:

misc buffers

*scratch* can stay, because it was there when emacs first started.

  • With ibuffer (which you seem to be using), you can group at least some of the buffers (e.g. the magit buffers) and deal with them in one blow - that should take care of 80% of the problem. See this example of dealing with ERC buffers,instead of magit buffers, but it should be close.
    – NickD
    Commented Apr 5, 2021 at 3:55
  • 1
    If I understand correctly, you want all buffers that aren't scratch to be killed, correct? Commented Apr 5, 2021 at 12:42
  • What @coffeepenbit asked. It's not clear what OP means by "this kind of 'miscellaneous' buffers".
    – Drew
    Commented Apr 5, 2021 at 15:35
  • (because they were there at emacs startup) what should remain is: *scratch* *Messages* *Warnings**Compile-Log* Commented Apr 7, 2021 at 12:35

2 Answers 2


If you use Icicles then you can quickly kill any or all buffers using just C-x k. Use one or more patterns (in the minibuffer) to match the buffers you want to kill, then use C-! to kill all those that match.

You can thus do this on the fly -- no need to open any special buffer, mark buffers etc. You can match using regexps, use multiple match patterns, etc.

See Act On All Candidates. See also Buffer-Name Input.


Based on your question, I am going to assume you want to kill all buffers except *scratch*

This function does that:

(defun cpb-kill-all-buffers nil
  "Kill all buffers except *scratch*"
  (mapcar 'kill-buffer (buffer-list))
  ;; Kill all other windows otherwise you will have many scratch windows.
  ;; reamining.
  • what should remain: *scratch* *Messages* *Warnings* *Compile-Log* Commented Apr 9, 2021 at 17:43

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.