Tuesday, June 28, 2011

Distinguish buffers of the same filename in Emacs

Have you ever opened multiple files of the same name only to find you can't tell which buffer holds which file? By default, Emacs adds a <number> postfix to the name of subsequent buffers opened which has the same filename as the filename of a preexisting buffer. Sometimes, it is not convenient to remember which postfix tag goes with which file. The solution is to use Uniquify. Uniquify postfixes the buffer name with the directory name of the file. Add the following to your .emacs file.
(require 'uniquify)
(setq uniquify-buffer-name-style 'post-forward-angle-brackets)
You can customize uniquify-buffer-name-style. Read more with C-h-v uniquify-buffer-name-style.


David said...

COOL. You saved my live :)

It even automatically switches to the parent of the parent directory, if the direct parent is not enough to distinguish them.

Raimon Grau said...


You're making my .emacs grow and grow and grow... :)

tsengf said...

Glad you like it. :)