Opening files in Vim using Fuzzy Search

Edan Maor picture Edan Maor · Mar 3, 2010 · Viewed 33.9k times · Source

I'm looking for a way to make Vim have the ability to open a file by fuzzy-searching its name.

Basically, I want to be able to define a project once, and then have a shortcut which will give me a place to type a file name, and will match if any letters match up.

This kind of functionality exists in most editors I've seen, but for the life of me I can't understand how to get Vim to do this.

Note that I'm looking for something that won't require me to have any idea where in my directory tree a file is. I just want to be able to open it by the filename, regardless of what directory it's in.

Thanks

Answer

Chris Knadler picture Chris Knadler · Jun 26, 2013

There are two great vim plugins for this.

ctrlp:

  • Written in pure VimL
  • Works pretty much everywhere
  • Supports custom finders for improved performance
  • Most popular fuzzy search plugin for Vim

Command-T:

  • Written in C, VimL and Ruby
  • Fast out of the box
  • Requires +ruby support in Vim
  • Recommends Vim version >= 7.3

EDIT:

I use CtrlP with ag as my custom finder and it's incredibly quick (even on massive projects) and very portable.

An example of using ag with CtrlP:

if executable('ag')
  " Use Ag over Grep
  set grepprg=ag\ --nogroup\ --nocolor

  " Use ag in CtrlP for listing files. Lightning fast and respects .gitignore
  let g:ctrlp_user_command = 'ag %s -l --nocolor -g ""'
endif