Ibuffer: Dired for Buffers

Ibuffer is a massive improvement on the buffer-menu function which is brought up by C-x C-b.It allows dried-like manipulations of your buffers, as well as font locks and sorting. It’s actually better than buffer-menu in pretty much every way, so if you haven’t switched to using it instead, I would highly recommend it. One of the more useful things it lets you do are: file buffers by major-mode, and then performing a replace-regexp on all marked files. You can select buffers by major mode using %m, and Q with then start a query-replace.

Another useful feature of ibuffer is it’s filtering, with ‘/’ as a prefix. Once you open ibuffer, you can filter the results down and operate on subgroups of buffers. For example, /n emacs will only show buffers in with ‘emacs’ in the buffer-name. You can also change the sort order with ’s’. Like Dired, * and % prefixes work for marking buffers.

Setting ibuffer up is relatively easy, although there is a ton of configuration you can do if you want. I’ll tell you about what I do, which is fairly minimal, but M-x customize-group ibuffer will give you all the ways to customize ibuffer. To use ibuffer instead of buffer-menu, add the following to your initialization:

(require 'ibuffer)

This just loads ibuffer. It comes with GNU Emacs, so you should already have the library without having to download it.

(setq ibuffer-default-sorting-mode 'major-mode)

This options control how lines in the ibuffer window are grouped. By specifying the sorting mode as ‘major-mode, I indicate that I want ibuffer to group buffers of the same type together. Another common sorting order is ‘recency, which orders them from most recently viewed to last viewed. Other options include ‘lexographic, ‘buffer-size, and ‘file-name.

(setq ibuffer-always-show-last-buffer t)
(setq ibuffer-view-ibuffer t)

These lines specify to ibuffer which buffers should be in the ibuffer menu. The first line specifies that it should always show the last buffer we were in, even if it would usually hide it. The second line specifies that the *Ibuffer* buffer itself should be in the buffer list - I just like having a complete list of my buffers to start with.

(global-set-key  (kbd "C-x C-b")        'ibuffer-other-window)

Since ibuffer is so much better than buffer-menu, you should just replace the C-x C-b keybinding to call ibuffer instead of buffer-menu.

Tags:

2 Responses to “Ibuffer: Dired for Buffers”

  1. Basu says:

    Ibuffer is awesome. I actually use a custom grouping scheme which matches both modes and filenames into common groups. For example, if I’m coding Python, it’ll pull together open file buffers and interpreters into a single Python grouping. Currently I have dired buffers separate, but I might pull them into my by language groupings. If you’re going that route, you might want to turn off showing empty buffers by (setq ibuffer-show-empty-filter-groups nil). Oh the joys of programmable tools.

  2. memnon says:

    Great series on emacs configuration/packages.
    Lots of goodies for a newbie like me ;)
    Thanks for taking the time to share!

Leave a Reply