M-x all-things-emacs

Giving ido-mode a Second Chance

May 19th, 2008 by Ryan McGeary · 126 Comments

Stuart Halloway’s recent screencast titled What You Can Learn From ido.el convinced me that I need to give ido-mode another look, especially since I didn’t realize it had support for flex (aka fuzzy) matching. I was always envious of the fuzzy matching that TextMate users received when finding a file in a project.

I’ve tried ido in the past, but it always turned me off. Today I realized why, and I was finally motivated enough to find a fix. I am a big fan of tab-completion everywhere, so when tab-completion doesn’t work like I expect, I get upset. As it turns out, this is why I (unfairly) disliked ido-mode at first. Due to some other trickery that I would rather not go into, I was guaranteeing that <tab> in the minibuffer would always call minibuffer-complete, which broke the tab behavior in ido:

(define-key minibuffer-local-map [tab] 'minibuffer-complete)

In summary, I’m a doofus. I should probably re-investigate the need for the above mapping; it was necessary because of a global key binding that I shouldn’t have made global in the first place. Without going down that rat hole just yet, here’s my workaround for now:

(ido-mode t)
(setq ido-enable-flex-matching t) ; fuzzy matching is a must have
;; This tab override shouldn't be necessary given ido's default 
;; configuration, but minibuffer-complete otherwise dominates the 
;; tab binding because of my custom tab-completion-everywhere 
;; configuration.
(add-hook 'ido-setup-hook 
          (lambda () 
            (define-key ido-completion-map [tab] 'ido-complete)))

I’m going to give ido-mode a fair chance this time, and I think I’m going to like it. I anticipate growing my custom ido configurations in the near future, and ido-mode could easily make it as a package fave. Thanks Stu.

For those of you who have already realized the power of Interactive Do, what power tricks do you recommend?

Update: Flex or fuzzy matching is the ability to match any item containing the characters in the given sequence. For example, “mwc” might match a file named “my_wicked_class.rb.”

Tags: ido · tips

126 responses so far ↓

  • 1 Petteri // May 19, 2008 at 6:21 pm

    Chris Done demostrated on Emacswiki how you can use ido for command completion ( http://www.emacswiki.org/cgi-bin/wiki/InteractivelyDoThings#toc5 ). Ii is really nice trick. Highly recommend it.

  • 2 MikeH // May 19, 2008 at 7:05 pm

    Have you ever tried Icicles? IDO looks like the same type of thing, only that Icicles is for buffers, files, commands, etc. You use Shift-Tab with that, so it doesn’t interfere with tab-completion everywhere.


    If you have used Icicles, how is IDO different?

  • 3 Derek // May 19, 2008 at 7:25 pm

    After entering ido-find-file, you may find you want to switch to an already open buffer, in which case you can just press C-b.

    More often, I want to drop to dired-mode from ido-find-file, where pressing C-f switches to the default find-file interface, from which dired is a C-m/enter away (this is a superior strategy to ido-show-dot-for-dired IMHO, which forces extra cycling). I also hit an extra C-f when typing the name of a new file so it doesn’t jump directories on me based on part of the file name.

    Also useful from ido-find-file is C-e, which lets you edit the file name. I use this all the time when I need to kill a section of the file name for yanking into a buffer, e.g. for an image path in an HTML or CSS file.

  • 4 Ryan McGeary // May 19, 2008 at 7:55 pm

    Derek, good tips. You can also just type C-x C-d or my preference C-d to drop to dired directly from ido-find-file assuming you’ve already completed the directory name.

  • 5 Ryan McGeary // May 19, 2008 at 7:59 pm

    MikeH, I’ve read about icicles, but it’s massiveness scares me. Maybe someone can convince me to give it a try.

  • 6 anon // May 19, 2008 at 8:30 pm

    ibuffer is nice for managing buffers in bulk.

  • 7 Max // May 20, 2008 at 1:06 am

    Usually I am using ido-regexp to open and switch files/buffers. This seems better than that one. Also I rarely use Tab to do completion on ido since Ctrl-s/r could switch the file names. that’s not bad.

    About M-x completion, I am using icomplete-mode. Not sure what difference between it and ido.

    Anyway, ido is really awesome and can not live without it.

  • 8 Juri Pakaste // May 20, 2008 at 5:36 am

    I’ve been using ido for ages, although never really taken a look if I’m missing on some features. I gave icicles a try recently but it feels like there’s just too much stuff there and it’s noticeably slow, whereas opening files or switching buffers with ido feels just as snappy as the normal Emacs commands.

  • 9 Anselm // May 20, 2008 at 7:12 am

    I’ve also tried icicles several times, but always found it foreign, uncomfortable in a way. Maybe I could configure it to do what I want, but I didn’t make the effort.

  • 10 Anselm // May 20, 2008 at 7:18 am

    I once hacked ido to support bookmarks, see http://www.emacswiki.org/cgi-bin/wiki/InteractivelyDoThings#toc6 . Before I had to work like this: C-x C-f (drops me into ido-find-file), (realize, that I need to go to a directory far away), C-g, C-x r b (complete my bookmarks name, this will be a directory), C-x C-f again, and finally I get to the file I want. Now I can press M-C-b in ido-mode to select a bookmark, and then go on looking for a file from there.

    Looking at the standard keybindings again, ido-restrict-to-matches, bound to C- looks really useful.

  • 11 MikeH // May 20, 2008 at 3:04 pm

    The Maintainer of Icicles is good at working with you with problems. I upgraded around Feb and had extreme slowness and we worked back and forth a lot trying to track down why.

    Icicles is compelling because it includes fuzzy matching for buffers, files, and commands and even strings in your buffer, if you take the time to set it up. I can’t live without it.

    But IDO is interesting in nothing but it’s speed and the (obvious) fan-base.

  • 12 Steve L // May 22, 2008 at 3:34 pm

    I don’t know… I can’t for the life of me get flex matching to work in ido. I have a relatively clean emacs install, too, seeing as how I just installed and started using it only a few days ago.

    I even tried adding your final lambda block to try to override anything I may have done to b0rk the behavior, and still no dice.

    Say I’m browsing a directory that has a file called “check_probe_export.py”, if I type “cpe” or “cpex”, etc … I reckon these should match, but it doesn’t.

    How would I go about smoking this problem out?

  • 13 Ryan McGeary // May 22, 2008 at 7:33 pm

    Steve L, Yes, “cpe” or “cpex” should flex match “check_probe_export.py”

    To debug, I’d start with checking versions of both emacs and ido.el. I currently run emacs v22.2.50.2 (M-x version) and use the ido-mode that comes with it (a derivative of ido v1.57).

    I don’t think versions prior to ido v1.57 had flex matching as an option, so I’d start with making sure you’ve got the latest.

  • 14 piyo // May 23, 2008 at 3:17 pm

    Thanks for this great site and topics.

    What a coincidence! This post shows up the week I started using ido-find-file. Truth be told, I first used ido with erc and recentf way before that. However initially I found ido-find-file to be a little annoying on the drop down to dired. Thanks to the comments, I learned about C-d, great!

    Regarding customizing ido, I live mainly in Windows so I create buffers and files with spaces in them. ido gets in the way of that so I bind the spacebar (“SPC”) to self-insert-command (look at ido-completion-map for details). Also, you can reuse ido for your own prompting interface, like toggling minor modes by name with prompting, sweet. xsteve of psvn.el fame has the tip for using it with recentf (recent file history):
    http://www.xsteve.at/prg/emacs/power-user-tips.html (xsteve-ido-choose-from-recentf)

    I still have to figure out how to shut off that autocomplete from history feature in ido-find-file. I really want to create a new file here with the same name as something else I visited (.gitignore, etc). Stop trying to be so smart, ido!

    Your “second chance” angle reminds me of the trouble I had using tramp and sudo (eg M-x find-file /sudo::/etc/hosts ENTER) I finally got motivated to fix it and it turns out it was because I use zsh and TRAMP doesn’t work with it out of the box. The bundled FAQ has the solution (RTFM?!). I had to make a new local user account and added bits and pieces to figure out what was going on. Perhaps this is the best method to trying new things in Emacs, though it feels really tedious.

  • 15 Steve L // May 23, 2008 at 4:28 pm

    Thanks for the tips … I had initially used the latest ido from their site (didn’t rely on local copy since I need to run emacs both locally and remotely), but still don’t know what the deal is.

    Also using GNU Emacs v. 22.2.1 (latest Carbon Emacs).

    Anyway, I reckon I must be doing something dumb. Once I have more time to figure this out, maybe I’ll just turn off any custom things I’ve installed and start adding things back slowly to see what’s up.

    I’ll post back here if/when I figure out what the problem was.


  • 16 Vikram Pawar // May 28, 2008 at 8:52 pm

    I have just started learning Emacs couple of weeks back. I was lucky to look at Ido and am addicted to Emacs since. Just remember that you can type C-f to get back to regular find file.

  • 17 Pete L. // May 30, 2008 at 2:49 am

    I’ve used ido a long time and depend on it now. I use the following settings:

    (defun my-ido-ignore-buffers (name)
     "Ignore all c mode buffers -- example function for ido."
     (with-current-buffer name
       (cond ((or (derived-mode-p 'cvs-mode) (derived-mode-p 'sql-interactive-mode))
              (string-match "^ ?\\*" name)))))
    (setq-default ido-ignore-buffers '(my-ido-ignore-buffers)
                                ido-auto-merge-work-directories-length -1)
    (ido-everywhere 1)

    everywhere allows for ido type buffer switching.. which is nice.

    I’ve taken to writing a lot of my scripts using ido-completing-read as well… which gives all my custom methods that require input the same type of support.

    The most common sub-command keybindings I use are C-s / C-r (ido-next-match) / (ido-prev-match), C-j (ido-select-text) and C-x f (ido-fallback-command) for when I need to edit the completions.

    I have tried icicles and didn’t like it… compared to ido it’s pretty complex. I prefer the simplicity of ido.

  • 18 Juan on programming » Blog Archive » Uniquify and ido // Jun 16, 2008 at 9:27 pm

    [...] just added ido to my config today based on a post I found at the emacs blog. It might take a bit of getting used to but we’ll see how that [...]

  • 19 Lin Zhu // Aug 21, 2008 at 7:42 pm

    Steve L,

    By any chance did you have ido-enable-regexp turned on? That would disable flex matching.

  • 20 Luke // Oct 27, 2008 at 12:00 pm

    When I hit RET on a completed directory, ido always opens it with dired by name. This is really annoying because it makes it impossible to advance through a directory tree to reach a certain file without leaving a trail of ten thousand dired buffers.

    I’m using GNU Emacs

  • 21 blog.andyobrien.com » Using Emacs again // Jan 26, 2009 at 1:18 pm

    [...] is an excellent source for tips and links on Emacs.  I particularly enjoyed his post “Giving ido-mode a Second Chance”. The referenced screencast really drove home the importance of having an editor with a great lower [...]

  • 22 Adam Bergmark // Dec 28, 2009 at 9:32 pm

    One annoying feature in ido is that it does a search for the input if you wait too long to pick files. Anyone know how to disable this?

  • 23 Ryan Thompson // Apr 29, 2010 at 7:17 am


  • 24 nypermems // Oct 22, 2010 at 4:18 am

    NiksLesy 0 Excellent topic

    discount UK