3

I want to kill all the buffers which start with info, I typed C-x-k info*<*>, it shows "no match".
So I know that I cannot use * to stand for all characters.
What is the correct expression it should be? Any help would be grateful.
This is my screenshot. Please have a look.
emacs buffer list window

bearer1024
  • 159
  • 1
  • 1
  • 8
  • What I've been doing for years (decades, actually) is: C-x C-b then create a macro to (regex) search for the next file that matches and flag it for deletion. I repeat the macro until all matching buffers are flagged, then I execute. Works great when you're moving directories around and the buffers no longer point at the right spots. Wish Emacs had an "occurs" function for the Buffer List that would flag matches for deletion / processing. – GLRoman Oct 20 '21 at 23:18

2 Answers2

7

M-x kill-matching-buffers is a standard command for this.

How do I answer y automatically (kill-matching-buffers asks if I should kill a modified buffer)? may also be of interest (although I'm not actually recommending doing that in general).

So I know that I cannot use * to stand for all characters.

.* will match zero or more non-newline characters, but you don't need to use that here, as kill-matching-buffers command does not require a match on the entire name. ^info would match your (stated) requirement.

I encourage you to read C-hig (emacs) Regexps to learn about the syntax of regular expressions in Emacs.

Community
  • 1
  • 1
phils
  • 71,335
  • 11
  • 153
  • 198
0
  1. Your buffers have names *info* and *info*<N>, N = 3..16. C-x k *info TAB TAB shows you all matches for the buffers you want to kill. But C-x k lets you kill only one at a time.

  2. If you use library Icicles then C-x k is a multi-command, which means that it can kill multiple buffers, individually or together. (And Icicles lets you pattern-match using regular expressions. But you don't need that here.)

    In this case, you just do C-x k *info TAB C-!, to kill all of the *info buffers.

    C-! applies the action to all objects that match your current input pattern.

Drew
  • 29,895
  • 7
  • 74
  • 104
  • got your mean, I guess u mean that even if I use regex I still cannot kill all buffers in once time because C-x k naturally support killing only one at a time. And Icicles library can help me kill multiple by using C-! other than using regex? – bearer1024 Feb 24 '17 at 17:27
  • Yes. For an Icicles multi-command, `C-!` applies the action of the base command to each current completion candidate. Regardless of the pattern you use to match completion candidates (regexp or not), whatever those matching candidates are they will each be acted on. In this case, `C-x k` is multi-command `icicle-kill-buffer` (when Icicle mode is enabled), and the action is to kill a candidate buffer. `C-!` kills all of them. – Drew Feb 24 '17 at 23:27