A Fuzzy Finder in Five Lines

What wildoptions=fuzzy does not do

Vim has a fuzzy value for wildoptions, and it is the obvious thing to reach for. But the manual is explicit:

Currently fuzzy matching based completion is not supported for file and directory names and instead wildcard expansion is used.

So it will not fuzzy-match filenames. The real mechanism is two other pieces.

findfunc and matchfuzzy()

Vim 9.1 added findfunc, which lets you replace what :find searches, and Vim ships matchfuzzy(), which ranks a list against a pattern. Together they are a fuzzy file picker in five lines:

set findfunc=Find
func! Find(arg, _)
  let files = filter(expand("**", 1, 1), "!isdirectory(v:val)")
  return empty(a:arg) ? files : matchfuzzy(files, a:arg)
endfunc
  • expand("**", 1, 1) walks the whole tree below you
  • filter(... "!isdirectory(v:val)") drops folders, leaving files
  • empty argument → hand back everything, so the menu shows the lot
  • otherwise → let matchfuzzy rank them

Save it and source it without restarting:

:w | so %

The result

:find thand          " -> tests/test_handlers.py
:find srout          " -> src/api/routes.py

Four letters, matched across a folder boundary. Not a prefix, no wildcard. A fuzzy file finder with nothing installed.

Vim’s own manual documents this pattern under :h fuzzy-file-picker.