Selecta on Vim using 'wildignore'

As moving to boxen I also removed all my vim plugins because I'm adding them back using Puppet rather than Git submodules.

One plugin that I've used a lot was Command-T, fuzzy search files is a big productivity boost when you are a developer. But one of the problems with Command-T is that it requires compilation, is not something that you just load and you are done. Recently Gary Bernhardt created the Selecta fuzzy finder, which can be used for anything that spits output to standard out and reads from standard in (which means almost every Unix command known).

Using Selecta on Vim is just a read the docs away, Selecta is input agnostic in a sense and actually doesn't known anything about Vim. If you check out the Vim function you will see that it just gets the output of a find command. The only thing I missed right away was Command-T used to respect my wildignore option on Vim, so I did a small function to recreate the find command based on my wildignore. Here it goes:

function! FindWithWildignore()
  let excluding=""
  for entry in split(&wildignore,",")
    let excluding.= (match(entry,'*/*') ? " ! -ipath \'" : " ! -iname \'") . entry . "\' "
  return "find * -type f \\\( " . excluding . " \\\)"

The thing to note is that I use -ipath or -iname depending on the entry because I might ignore files or a full directory on wildignore. Plug this into your SelectaCommand and now settings on wildignore will be excluded from your choices, like so.

nnoremap <leader>t :call SelectaCommand(FindWithWildignore(), "", ":e")<cr>

You can check out the full vimrc here.

Published in Dec 27, 2013