Ignoring .gitignore files in Unite.vim

Everyone loves Unite's file_rec/async file searcher, but it can be slow and unhelpful if it's not tuned properly.

The first thing that can be done to make Unite's file search faster is to use ag instead of the default, find. Unite is pretty smart, and it will use ag if it's available, so a simple brew install ag will get you rolling on Mac (installation instructions are on Github for other platforms).

By default, ag ignores files which are in your project's .gitignore (or .hgignore), but that behavior has been disabled in Unite. Luckily, we can reenable it pretty easily by changing the command Unite uses to search files for file_rec/async by doing something like:

let g:unite_source_rec_async_command= 'ag --nocolor --nogroup --hidden -g ""'

in vimrc. You may want to wrap this with a if executable('ag') if you're trying to keep your config portable.

After making this change, you may see inconsistent results in your Unite buffer because of the Unite cache. To clear the cache, <C-l> within a unite buffer.

Hopefully this speeds up your filematching!

6 Responses
Add your response


One of the best things I've found on this site. Thanks

over 1 year ago ·

Does this work with the current version of Unite? Can't get it working.

over 1 year ago ·

In the latest version of unite:

let g:unite_source_rec_async_command='ag --nocolor --nogroup -g ""'
over 1 year ago ·

Thanks, man! I

over 1 year ago ·

Kudos for refreshing the unite cache. It was driving me crazy!

over 1 year ago ·

Looks like it is array now:

let g:unite_source_rec_async_command = ['ag', '--follow', '--nocolor', '--nogroup', '--hidden', '-g', '']
over 1 year ago ·