Monday, January 21, 2008

Emacs Tip #11: uniquify

Do you dislike the buffer names Emacs generates when two files have the same name? e.g. "myfile.txt" and "myfile.txt<2>"

A package 'uniquify' changes the default naming of buffers to include parts of the file name (directory names) until the buffer names are unique.

For instance, buffers visiting the files:


/u/mernst/tmp/Makefile
/usr/projects/zaphod/Makefile

would be named

Makefile|tmp
Makefile|zaphod

respectively (instead of "Makefile" and "Makefile<2>").

There are other naming schemes possible.

I use this to my .emacs:

(require 'uniquify)
(setq uniquify-buffer-name-style 'reverse)
(setq uniquify-separator "/")
(setq uniquify-after-kill-buffer-p t) ; rename after killing uniquified
(setq uniquify-ignore-buffers-re "^\\*") ; don't muck with special buffers


For the *info* page,

C-h i m emacs RET s uniquify RET

3 comments:

stassats said...

Thanks, very useful.

Unknown said...

Quick tip if setting the uniquify variables via customize:

M-x customize-group RET uniquify

For Uniquify Ignore Buffers Re, one backslash is sufficient: ^\*

Adam said...

Amazing! I love it.