Is there an easy way to exclude files for which FuzzyFinder searches?
Asked Answered
A

3

17

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?

Ayeshaayin answered 9/11, 2010 at 11:10 Comment(0)
T
21
let g:fuf_file_exclude = '\v\~$|\.o$|\.exe$|\.bak$|\.swp$|\.class$'

Use :help fuf-options for more details.

Trappings answered 9/11, 2010 at 12:6 Comment(3)
Thanks for the reply, i am still learning my way around vim and its plugins.Ayeshaayin
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!Trappings
Remember the \v at the start if you want regular expressions! Also use g:fuf_coveragefile_exclude if you are using FufCoverageFile.Edgar
S
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
Sybilsybila answered 1/2, 2013 at 7:0 Comment(3)
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 lcds?Apotheosize
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.Apotheosize
Thanks. One bugfix - should skip over empty linesStrength
A
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>
Apotheosize answered 26/6, 2013 at 14:25 Comment(1)
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?Mudpack

© 2022 - 2024 — McMap. All rights reserved.