One reason, why I blog about emacs is that I’m often learning new things from people who leave a comment on my blog. My latest cool toy, thanks to a mention from foo is ibuffer. I had heard of it already (and had a vague idea of what it does), but had not investigated it any depth.
So, what does ibuffer do and why is it cool? It is a powerful substitute for
list-buffers which by default is bound to
C-x C-b. You can get started by typing
M-x ibuffer <RETURN> h (for help).
The main features provided are:
- sorting (with a
- filtering (with a
- marking (with
- processing (which covers a multitude of sins)
I like to sort the buffers lexicographically before I begin with
s a. If it turns out I always do this, I’ll customize
I’ve come up with a few simple recipes so far:
* s(mark star buffers)
D(delete all marked buffers)
* r k(remove read-only buffers from ibuffer)
% n(mark buffers by regex)
One thing that ibuffer doesn’t have is a function that compares two marked buffers. However, its easy enough to add one.
(defun ibuffer-ediff-marked-buffers () (interactive) (let* ((marked-buffers (ibuffer-get-marked-buffers)) (len (length marked-buffers))) (unless (= 2 len) (error (format "%s buffer%s been marked (needs to be 2)" len (if (= len 1) " has" "s have")))) (ediff-buffers (car marked-buffers) (cadr marked-buffers)))) (define-key ibuffer-mode-map "e" 'ibuffer-ediff-marked-buffers)
We might as well replace the default binding for
(global-set-key (kbd "C-x C-b") 'ibuffer)