16

I am using FuzzyFinder and was wondering how I could instruct FuzzyFinder to exclude files it searches for. For now I have modified the plugin code but there must be a more easy way.

I want to exclude .class files from popping up in the result. Any hints/tips on how can I instruct FuzzyFinder to skip these files?

Cascabel
  • 479,068
  • 72
  • 370
  • 318
Marco
  • 15,101
  • 33
  • 107
  • 174

3 Answers3

21
let g:fuf_file_exclude = '\v\~$|\.o$|\.exe$|\.bak$|\.swp$|\.class$'

Use :help fuf-options for more details.

ceyko
  • 4,822
  • 1
  • 18
  • 23
Benoit
  • 76,634
  • 23
  • 210
  • 236
  • Thanks for the reply, i am still learning my way around vim and its plugins. – Marco Nov 09 '10 at 20:15
  • When you deploy a plugin, also deploy the doc, and run `:helptags /path/to/the/doc/folder`, almost all good plugins have a decent documentation here! – Benoit Nov 09 '10 at 20:18
  • 5
    Remember the `\v` at the start if you want regular expressions! Also use `g:fuf_coveragefile_exclude` if you are using `FufCoverageFile`. – robbrit Jan 11 '13 at 15:08
5

With the help of Benoit:

"FuzzyFinder should ignore all files in .gitignore
let ignorefile = ".gitignore"
if filereadable(ignorefile)

  let ignore = '\v\~$'
  for line in readfile(ignorefile)
    let line = substitute(line, '\.', '\\.', 'g')
    let line = substitute(line, '\*', '.*', 'g')
    let ignore .= '|^' . line
  endfor

  let g:fuf_coveragefile_exclude = ignore
endif

And on the eighth day God was awakened by a terrible noise, and he did create a script to locate the subject of his disturbance. Thereupon finding bugs, he smote them. And it was good once more.

Brandon
  • 917
  • 10
  • 11
  • 2
    This definitely works from your `.vimrc` if you source your .vimrc after setting the `lcd` (local current directory), but if you switch tabs or windows to another project with a different `lcd`, you have to re-source your `.vimrc` and it clobbers the variable globally. Is there any way to do this per-window with different `lcd`s? – Neil Jun 26 '13 at 12:55
  • Make sure to set `g:fuf_file_exclude` and `g:fuf_dir_exclude` to the `ignore` variable as well. This will make `FufFile` and `FufDir` work as expected. – Neil Jun 26 '13 at 13:48
  • Thanks. One bugfix - should skip over empty lines – ygrek Apr 17 '15 at 05:26
1

This is the most automatic solution that will work in different windows and tabs that have their own lcd (local current directory).

Since Vimrc doensn't have the concept of setting exclude variables per-window or per-tab, you have to reset the exclude variables each time your run FufFile or related functions.

Put this in your .vimrc:

" FuzzyFinder
" -----------------------------------------------------------------------------
function! FufSetIgnore()

    let ignorefiles = [ $HOME . "/.gitignore", ".gitignore" ]
    let exclude_vcs = '\.(hg|git|bzr|svn|cvs)'
    let ignore = '\v\~$'

    for ignorefile in ignorefiles

        if filereadable(ignorefile)
            for line in readfile(ignorefile)
                if match(line, '^\s*$') == -1 && match(line, '^#') == -1
                    let line = substitute(line, '^/', '', '')
                    let line = substitute(line, '\.', '\\.', 'g')
                    let line = substitute(line, '\*', '.*', 'g')
                    let ignore .= '|^' . line
                endif
            endfor
        endif

        let ignore .= '|^' . exclude_vcs
        let g:fuf_coveragefile_exclude = ignore
        let g:fuf_file_exclude = ignore
        let g:fuf_dir_exclude = ignore

    endfor
endfunction

# Bonus: My custom key mappings for FuzzyFinder
# Calls the function to set the exclude variables, then runs FuzzyFinder
nn <Tab>   :call FufSetIgnore() <BAR> :FufFile<CR>
nn <S-Tab> :call FufSetIgnore() <BAR> :FufFile **/<CR>
nn <F3>    :call FufSetIgnore() <BAR> :FufFile **/<CR>
Neil
  • 24,551
  • 15
  • 60
  • 81
  • This is really cool, but for some reason, it doesn't seem to actually work the first time I call FF. I have a very large file tree (and i don't need to index the dependencies), and each first load takes almost a minute. Is there some way to have this run before fuzzy finder tries to build an index at all? – counterbeing Nov 20 '14 at 01:47