This is the start of a series on our favorite emacs packages. Some of these packages are part of emacs core, some aren’t (but we could argue should be). I use iswitchb-mode at least a hundred times a day. iswitchb is one of the features of emacs that I rave about whenever I try to explain why I am still using a 30-year old editor. From the package commentary:
As you type in a substring, the list of buffers currently matching the substring is displayed as you type. The list is ordered so that the most recent buffers visited come at the start of the list. The buffer at the start of the list will be the one visited when you press return. By typing more of the substring, the list is narrowed down so that gradually the buffer you want will be at the top of the list. Alternatively, you can use C-s and C-r to rotate buffer names in the list until the one you want is at the top of the list. Completion is also available so that you can see what is common to all of the matching buffers as you type.
The key stroke C-x b brings up the iswitchb mini-buffer, and with a few key strokes the file you want is open. My normal mode of operation is to load the project I am working on into the emacs file name cache, and then use iswitchb to switch between the files. In order to use iswitchb in this manner you will need iswitchb-fc, and a means for populating the file name cache.

Some of the nice features of iswitchb include filtering out buffers that you don’t want to see, and limiting how many files are shown in the minibuffer by customizing the iswitchb-max-to-show variable. Additionally, you can kill a buffer from within iswitchb by typing C-k. The following is a snippet from my .emacs:
;;============================================================ ;; iswitchb ;;============================================================ (require 'iswitchb) (iswitchb-mode 1) ;;============================================================ ;; iswitchb ignores ;;============================================================ (add-to-list 'iswitchb-buffer-ignore "^ ") (add-to-list 'iswitchb-buffer-ignore "*Messages*") (add-to-list 'iswitchb-buffer-ignore "*ECB") (add-to-list 'iswitchb-buffer-ignore "*Buffer") (add-to-list 'iswitchb-buffer-ignore "*Completions") (add-to-list 'iswitchb-buffer-ignore "*ftp ") (add-to-list 'iswitchb-buffer-ignore "*bsh") (add-to-list 'iswitchb-buffer-ignore "*jde-log") (add-to-list 'iswitchb-buffer-ignore "^[tT][aA][gG][sS]$") ;;============================================================ ;; iswitchb-fc ;;============================================================ (require 'filecache) (load "iswitchb-fc")
There are other packages out there that do the same thing and even more. Even though I love iswitchb, I have been meaning to try icicles and/or the ido package since they seem to provide the same functionality on steroids. If you are an advocate of one of these other packages, I hope to hear from you. If you are not using any of these packages on an hourly basis then start today. The package is indispensable.
16 responses so far ↓
I was a frequent user of iswitchb, but I’ve switched to ido. I’m not an expert of ido, though. I don’t turn on everything, just the ido buffer mode.
I do however hook up recentf and ido together. This lets you match on files over your history instead of just buffer. I got that tip from xsteve: http://www.xsteve.at/prg/emacs/power-user-tips.html
Recentf’s file listing page now seems so slow to me.
I think this idea could substitute loosely for the above mentioned iswitchb-fc.
The nice thing about ido-mode is that it offers similar completion for commands other than switching buffers, for example you can use it when finding files with C-x C-f. You can also interface it from your own elisp code.
Awesome suggestion! I use emacs on a ton of computers so I like to use the stuff built into emacs. I showed my friend who uses kate as an editor how fast I can switch tabs now… he just didn’t understand how cool it was. Then we raced =)
Also try out icomplete-mode. It’s like iswitchb, but for minibuffer input (example: M-x commands).
I’ve been using iswitchb for a while, and I love it. I tried ido, but it actually interfered with one way in which I use emacs: when programming in a given project, I like to preload all of the source files in the project’s directory and just jump between them with C-x b. (Among other things, having everything loaded makes dabbrev-expand work very nicely.) Consequently, I often do ‘C-x C-f ~/directory/*.pas’. ido always interpreted that as a single file, while the standard emacs functions treat it as a globbing pattern. Thus, I stick with iswitchb.
iswitchb.el can also match against files you have recently visited, and which are not currently open (I call the concept “virtual buffers”, since you should be able to switch to recently used files as if they were just dormant buffers).
To enable this usage, just turn on recentf, then set `iswitchb-use-virtual-buffers’ to t. You can use the customize interface to do both.
John
Can’t / certainly don’t want to remember my time before iswitchb.
There is a great function in the comments of iswitchb.el named `iwitchb-exclude-nonmatching’. It allows to search for stuff like “.el” first, in order to limit the number of visible buffers.
ido is my preferred buffer-switching package. I seem to remember that it handles spaces in buffer names a bit more intelligently than iswitchb does.
Sounds really interesting, but when I type M-x iswitchb-mode , emacs tells Symbol’s function definition is void: define-obsolete-variable-alias. I don’t know what it means. Did you ever get that message while trying to use the package? What did you do, then? Thanks in advance.
@Phil:
In ido-mode, if you hit ‘C-x C-f C-f’ you get the “normal” find file function. So to open all your files at once, just do ‘C-x C-f C-f ~/directory/*.pas’
first: nice blog!
then: as for a buffer-manager: anything.el has been a nice companion so far
mark
first: nice blog!
then: as for a buffer-manager: anything.el has been a nice companion so far. see bills intro to it under Quicksilver for Emacs:anything.el
mark
@mark,
Thanks for the pointer. I will have to check out anything.el. I love Quicksilver.
The linked blog entry doesn’t mention anything-config.el which is really nice and has lots of predefined configurations for anything.el
See here for more information if you want to try it:
http://www.emacswiki.org/cgi-bin/wiki/Anything
Is there a way to make c-x b in ido also look at recentf?
@samuel – Have you tried any of these options from the Emacs Wiki
Leave a Comment