2

When using C-x C-f (ido-find-file) to open files use I can use M-s to enable fuzzy matching.

If I type C-x C-f then M-s and then enter the the fuzzy search string, things work as they should.

However if I type C-x C-f then enter the fuzzy string and then type M-s I get something like this in the minibuffer:

my-fuzzy-search[correct-completion]{some-totally-unrelated-file | correct-completion | ... }

Some unrelated file is always first in the list of results, and if I press enter here ido will open it. Is there a way to configure ido so that the correct match will be first in the list in this case?

  • FWIW, Ido does not really use what is usually called fuzzy matching. It uses what it calls flex matching (which is what Icicles calls scatter matching), which is kind of a poor man's fuzzy matching. (Nothing wrong with it - just saying...) – Drew Oct 30 '14 at 1:06
4

Ido doesn't have very smart fuzzy matching by default. Essentially, if you put in

horse

Ido will try to match

.*h.*o.*r.*s.*e.*

against its candidates. This isn't really how we think about matching, since we would expect a file literally called horse-feathers.txt to score higher than hogs-raging-senial.png.

Check out the flx-ido package. From the readme:

The sorting algorithm is a balance between word beginnings (abbreviation) and contiguous matches (substring).

The longer the substring match, the higher it scores. This maps well to how we think about matching.

In general, it's better form queries with only lowercase characters so the sorting algorithm can do something smart.

For example, if you have these files:

    projects/clojure-mode/clojure-mode.el
    projects/prelude/core/prelude-mode.el

If the search term was pre-mode, you might expect "prelude-mode.el" to rank higher. However because the substring match "re-mode" is so long, "clojure-mode.el" actually scores higher.

Here, using premode would give the expected order. Notice that the "-" actually prevents the algorithm from helping you.

uppercase letters

Flx always folds lowercase letters to match uppercase. However, you can use uppercase letters for force flx to only match uppercase.

This is similar to Emacs' case-folding. The difference is mixing in uppercase letters does not disable folding.

completing file names

Matches within the basepath score higher.

  • This works better, but I can still get situations where the completion I want is in [] brackets in the beginning, but further down in the {} list. If I write the beginning of a filename with wrong case, this file will end up further down the list, compared to a file with the same letters further apart but with the right case. However the first file will be shown within the square brackets. – snowape Oct 30 '14 at 5:22
  • Again, In general, it's better form queries with only lowercase characters so the sorting algorithm can do something smart. Why use Shift when you don't have to? – Sean Allred Oct 30 '14 at 17:01
  • When I write with all lowercase, and the match I want has some uppercase characters, then the situation in my first comment happens. – snowape Oct 30 '14 at 22:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.