Storm's Free Software Collection

ido.el - IDO mode

This is my "interactively do" package which provides replacements for the switch-buffer and find-file functions (and the various versions of these functions) for switching between buffers and opening files with an absolute minimum of keystrokes. The ido.el package borrows heavily from Stephen Eglen's iswitchb.el package (both in concepts and code), and provides the same functionality for switching buffers while expanding the functionality to cover opening files as well.

As you type in a substring, the list of buffers or files currently matching the substring are displayed as you type. The list is ordered so that the most recent buffers or files visited come at the start of the list.

The buffer or file 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 or file you want will be at the top of the list. Alternatively, you can use the right and left arrow keys (or C-s and C-r) to rotate buffer or file 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 or files as you type.

Installation of ido.el

To get the alternative switch-to-buffer and find-file functions in this package bound to the normal C-x b and C-x C-f key sequences, place the ido.el file somewhere on your load path, byte compile it, and insert the following lines in your .emacs file:
  (require 'ido)
  (ido-mode t)

Example: ido-switch-buffer

If you have two buffers called "123456" and "123", with "123456" the most recent, when you use ido-switch-buffer, you first of all get presented with the list of all the buffers
  Buffer:  {123456,123} 

If you then press 2:
  Buffer: 2[3]{123456,123}

The list in {} are the matching buffers, most recent first (buffers visible in the current frame are put at the end of the list by default). At any time you can select the item at the head of the list by pressing RET. You can also bring the put the first element at the end of the list by pressing C-s or [right], or put the last element at the head of the list by pressing C-r or [left].

The item in [] indicates what can be added to the input by pressing TAB. In this case, you will get "3" added to the input. So, press TAB:

  Buffer: 23{123456,123}

At this point, you still have two matching buffers. If you want the first buffer in the list, you simply press RET. If you wanted the second in the list, you could press [right] or C-s to move it to the top of the list and then RET to select it.

However, if you type 4, you only have one match left:

  Buffer: 234[123456] [Matched]
Since there is only one matching buffer left, it is given in [] and we see the text [Matched] afterwards. you can now press TAB or RET to go to that buffer.

If however, you now type "a" there are no matching buffers:

  Buffer: 234a [No match]
If you press RET or TAB, you will be prompted to create a new buffer called "234a".

Of course, where this function comes in really useful is when you can specify the buffer using only a few keystrokes. In the above example, the quickest way to get to the "123456" file would be just to type 4 and then RET (assuming there isn't any newer buffer with 4 in its name).

To see a full list of all matching buffer in a separate buffer, hit ? or press TAB when there are no further completions to the substring. Repeated TAB presses will scroll you through this separate buffer.

The buffer at the head of the list can be killed by pressing C-k. If the buffer needs saving, you will be queried before the buffer is killed.

If you find that the file you are after is not in a buffer, you can press C-f to immediately drop into ido-find-file.

Example: ido-find-file

Likewise, if you use ido-find-file, the list of files and directories in the current directory is provided in the same fashion as the buffers above. However, the files and directories are simply sorted in alphabetical order.

In addition to scrolling through the list using [right] and [left], you can use [up] and [down] to quickly scroll the list to the next or previous subdirectory.

To go down into a subdirectory, and continue the file selection on the files in that directory, simply move it to the head of the list and hit RET.

To go up to the parent directory, delete any partial file name already specified (e.g. using [backspace]) and hit [backspace]. You can also use [M-backspace] to delete the partial file name.

To go to the root directory (on the current drive), enter two slashes.
On MS-DOS or Windows, to select the root of another drive, enter X:/ where X is the drive letter.

You can quickly open a file in another directory if you have previously opened a file in that directory (also in an earlier emacs session) by typing (part of) the file name, and then hit [M-p] once or twice to look for the file in ido's work directory history.

In addition, ido-find-file will automatically search for the entered file name in the last 50 working directories if there are no matches in the current directory. To undo this search but keep the entered character(s) use [C-z], or simply delete backwards using [backspace] until you have a match.

If for some reason you cannot specify the proper file using or you can use C-e to edit the whole path name without the interactive parsing; terminate editing with RET. If the entered path is a non-existing directory, ido will offer to create the directory - or allow you to continue editing the path.

Alternatively, you can always press C-f to enter the normal, non-interactive find-file.

You can also press C-b to drop into ido-switch-buffer.

See the doc string of ido-switch-buffer and ido-find-file for full keybindings and features.

  (describe-function 'ido-find-file)


Since I discovered Stephen Eglen's excellent iswitchb package, I just couldn't live without it, but once being addicted to switching buffers with a minimum of keystrokes, I soon found that opening files in the old-fashioned way was just too slow - so I decided to write a package which could open files with the same speed and ease as iswitchb could switch buffers.

I originally wrote a separate ifindf.el package based on a copy of iswitchb.el, which did for opening files what iswitchb did for switching buffers. Along the way, I corrected a few errors in ifindf which could have found its way back into iswitchb, but since most of the functionality of the two package was practically identical, I decided that the proper thing to do was to merge my ifindf package back into iswitchb.

This is basically what ido (interactively do) is all about; but I found it ackward to merge my changes into the "iswitchb-" namespace, so I invented a common "ido-" namespace for the merged packages.


Naturally, infinite amounts of gratitude goes to Stephen Eglen who wrote iswitch-buffer mode - from which I ripped off 99% of the code for ido-switch-buffer and found the inspiration for ido-find-file. The ido package would never have existed without his work.

Revision History

  • Revision 1.56, 2002-01-05
    Don't use obsoleted insert-string in emacs 21.3
    Fixed: Don't bind backspace and M-backspace specifically for xemacs.

  • Revision 1.55, 2001-12-28
    Fixed ido-minibuffer-setup for xemacs (but ido still has problems is some areas with xemacs).
    Automatically look in list of ignored files or buffers [C-a] when there are no matches. Specifically, .. is now completed normally although it is ignored by default.
    Removed the ido-merge-work-directories variable which modified the functionality of M-p and M-n.
    The M-p and M-n commands now always go to the previous / next (matching) work directory in the history.
    New M-s command (ido-merge-work-directories) to actively search (and merge) the work directory history.
    Added ido-show-dot-for-dired to allow easy entry to dired from ido-find-file.

  • Revision 1.54, 2001-12-07
    Adapted key-binding fix from Bill Benedetto for (ido-mode 'buffer).
    Added find-file-read-only-other-window and find-file-read-only-other-frame.
    Adapted fix from Stephen Eglen to use select-frame-set-input-focus when available.

  • Revision 1.53, 2001-12-06
    Immediately fallback to non-ido find-file if ido-find-file is activated in a buffer whose default-directory is on a slow ftp host.
    C-k in ido-find-file offers to delete file at head of list.

  • Revision 1.52, 2001-11-24
    Fixed: Ignore error messages from `find' command in ido-wide-find-dirs-or-files.
    Added ido-slow-ftp-hosts and ido-slow-ftp-host-regexps to automatically fallback to standard find-file if visiting one of the matching hosts.
    Added ido-merge-ftp-work-directories; by default, ftp hosts are ignored when searching work directories.
    Added ido-cache-ftp-work-directory-time; by default, ftp host directories are cached for one hour without checking for new contents.
    Don't cache root directories on nt and ms-dos systems.

  • Revision 1.51, 2001-11-16
    Fixed ido-to-end: would clear ido-temp-list if applied to entire list.
    C-backspace now goes to parent directory without clearing current file name.
    Disable print-level and print-length limitations when saving history.
    Now check proper formatting of all loaded history data in ido-wash-history.
    Discard bogus elements.
    Added M-m to make-directory in current directory.
    Added M-f to search for a matching files using external find command.
    Added M-d to search for a matching directories using external find command.

  • Revision 1.50, 2001-11-05
    User input now interrupts auto merge.
    Fixed: maintain current input when switching between file and buffer selection.

  • Revision 1.49, 2001-10-30
    In emacs 21, now resizes minibuffer according to max-mini-window-height.
    Added ido-max-window-height to override max-mini-window-height.
    Added fix from Alex Schroeder for ido-max-prompt-path customization.
    Fixed: Input was not echoed in minibuffer when no matches; the fix uses a timer to perform auto-merge delay rather than sit-for.
    Replaced ido-auto-merge-delay by ido-auto-merge-delay-time (seconds).
    Don't auto-merge with 1 character only (so don't auto-merge on ~).
    M-k removes current directory from ido-work-directory-list.

  • Revision 1.47, 2001-10-15
    Added ido-decorations to allow more customization of ido minibuffer.
    Enhanced ido-wash-history to remove text properties from strings.
    In match list, strings whose prefix matches are now placed first.
    Fixed: Clear previous input string when C-g is used to quit minibuffer.
    Fixed: Restore previous matches when undoing merge using [backspace].
    Fixed: Avoid duplicates in ido-work-file-list.
    No longer uses pp to save ido history file.
    Added ido-read-file-name and ido-read-directory-name functions.

  • Revision 1.46, 2001-10-03
    Added ido-auto-merge-delay to delay auto merge operation by 500 ms waiting for more input.
    Corrected minor problems related to cycling through merged lists.

  • Revision 1.45, 2001-10-01
    Added C-o command to ido-find-file to copy file name from current buffer.
    Modified C-w to no copy extension if current directory hasn't changed.

  • Revision 1.44
    Use directory cache contents when creating merged directory list.
    Added ido-ignore-directories-merge.
    Fixed customize type for ignore lists to choice of regexps or functions.

  • Revision 1.43
    Added ido-merged-indicator and ido-indicator-face.
    Use directory file cache rather than work directory list when merging directories (ending in /)

  • Revision 1.42
    Don't auto-merge in write-file, dired, and list-directory
    Restore pre-merge state when backspacing or no merged matches found
    C-z now undoes last merge and returns to the pre-merge directory

  • Revision 1.41
    Ignore text properties in minibuffer contents (if yanked)
    Fixed: don't auto-merge in root to allow entry of ange-ftp hostnames

  • Revision 1.40
    Added ido-work-directory-list-ignore-regexps.
    Added ido-dir-file-cache and ido-max-dir-file-cache.
    Added automatic lookup in work directory history for files when no match.
    Added ido-merge-work-directories and ido-auto-merge-work-directories-length.

  • Revision 1.37, 2001-06-28
    Avoid corrupting .ido.last and check after load.

  • Revision 1.36, 2001-06-14
    Fixed handling of ~/ (was broken in 1.34)
    $VAR expansion how happens automatically when typing /
    Fixed: dired would store /path/./ rather than /path/ in work directory history.
    ido-write-file now disables ido-work-directory-match-only.

  • Revision 1.35, 2001-06-12
    Added work file history (on M-o and M-b)
    Fixed: allow entering dired with wildcard filename.
    C-w now inserts current buffer's file name.
    TAB scrolls *Ido Completions* buffer; when used at end of buffer, start from top, but now show all completions in the buffer.
    More customization: ido-completion-buffer-all-completions.
    Work file and directory lists can now be saved and loaded using
    M-x ido-save-history and M-x ido-load-history.

  • Revision 1.34, 2001-06-10
    Selection with keyboard or mouse now works in completion buffer.
    - New variable ido-completion-buffer (default *Ido Completion*).
    - Completion buffer is automatically removed when context changes.
    - Completion buffer contents are now sorted alphabetically.
    Fixed: ido-dired didn't put directory in work directory history.
    Added short description of how ido-find-file actually works.
    [M-backspace] now deletes word (if any) or last subdir like [backspace]

  • Revision 1.33, 2001-06-07
    When using multiple frames, ido-switch-buffer now shows current frame's buffers first.

  • Revision 1.32, 2001-06-06
    Added fixes and enhancements from Klaus Berndl:
    - New ido-separator variable.
    - Fixed documentation of various make-list-hooks.
    - Don't backspace past root directory.
    Fixed: default-directory of current buffer was changed by find-file fallback.
    Added ido-make-file-prompt-hook and ido-rewrite-prompt-path-rules variables.
    Added work directory history for ido-find-file [M-n] / [M-p].

  • Revision 1.31, 2001-05-30
    Changed package location to

  • Revision 1.30, 2001-05-21
    Dired now has . as default choice to make entering current directory easy.
    C-f now always falls back to non-ido version of current command.
    "../" is now handled like backspace (updir).
    Handle $VAR expansion in file names
    Disable show-paren-mode in minibuffer
    Fixed handling of / in directory paths
    Fixed unintended ange-ftp interaction in root directory.

  • Revision 1.29, 2001-05-14
    Use [C-e] to edit the input string (and path).
    Added idonized version of find-file-read-only [C-x C-r].
    Added idonized version of dired [C-x d].
    Added idonized version of list-directory [C-x C-d].
    Minor bug fixes.

  • Revision 1.24, 2001-04-17
    The directory history list is now saved in .ido.last file in home directory.
    Currently visited files are now moved to end of file selection list.

  • Revision 1.23, 2001-03-20
    Documentation fixes.

  • Revision 1.22, 2001-01-04
    Added: support for emacs 21.
    Added: Limit number of items shown in buffer/file list according to new variable ido-max-prospects. This gives rather significant speed improvements.

  • Revision 1.21, 2000-11-27
    Merged Klaus' modification into development version.

  • Revision 1.20, 2000-10-01
    Improved version from Klaus Berndl.
    Added: prefix macthing in addition to the normal substring-matching. Customized via ido-enable-prefix and toggled with ido-toggle-prefix [C-p].
    Added: highlighting for sub-directories in the alternative-list for better and faster overview. Customized via ido-subdir-face.
    Added: possibilty to customize for what function group (buffer and/or file handling) ido should be enabled. Look at ido-enabled.
    Fixed: file-functions (find, insert, write...) now handle the default-directory of the current buffer correctly.
    Fixed: Compatiblity for emacs without customize for deface too.

  • Revision 1.10, 2000-04-03
    Added "ido-record-commands" which causes ido commands to be registered in the command-history so they can be repeated by [C-x ESC ESC].
    Fixed: [C-x i] now only queries for file to insert once.
    Fixed: [C-x C-w] no longer reports [No Match].
    Fixed: ido-last-directory-history is ignored if directory no longer exists.

  • Revision 1.9, 2000-03-22
    Fixed: [C-x k] now uses current buffer as default choice even when matched by ido-ignored-buffers.
    Fixed: ido-find-file now works with ange-ftp.

  • Revision 1.8, 2000-03-21
    Added "interactive do" versions of more buffer and file related commands:
    [C-x C-v] ido-find-alternate-file
    [C-x C-w] ido-write-file
    [C-x i] ido-insert-file
    [C-x C-i] ido-insert-buffer (new binding)
    [C-x k] ido-kill-buffer

  • Revision 1.7, 2000-03-05
    Added "ido-enable-last-directory-history" which causes the last directory selected in a directory to be placed at the head of the item list presented by [C-x C-f].
    [C-l] now toggles a 'find-literal' flag (default off) which causes [C-x C-f] to open the file without conversion (i.e. literally/binary).

  • Revision 1.6, 2000-02-15
    Initial release.