24

I'm having a lot of trouble figuring out the syntax for the wildignore setting in Vim.

Suppose I want my file finder plugin (I use Ctrlp, which uses wildignore) to not search through hidden files and folders, that is, files and folders prefixed with a ..

How would I go about doing that?

ib.
  • 27,830
  • 11
  • 80
  • 100
Fawkes5
  • 1,001
  • 3
  • 9
  • 12

4 Answers4

10

Concerning ctrlp.vim and wildignore specifically, if you type :help ctrlp-options and read a bit, you will find:

Note #1: by default, wildignore and g:ctrlp_custom_ignore only apply when globpath() is used to scan for files, thus these options do not apply when a command defined with g:ctrlp_user_command is being used.

Thus, you may need to unlet g:ctrlp_user_command (possibly set to a default command) to actually use wildignore. For instance, in your ~/.vimrc, add:

if exists("g:ctrl_user_command")
    unlet g:ctrlp_user_command
endif
set wildignore+=.*
BenC
  • 8,729
  • 3
  • 49
  • 68
  • 3
    I had tried adding wildignore, custom_ignore and the ctrl_user_command was not set. Finally found the another answer @BenC provided on a similar question. The Ctrlp caches results so once you've found files you want to ignore they will still show regardless of what you put in the wildignore/custom ignore until the ctrlp cache is cleared. http://stackoverflow.com/questions/21017857/ctrlp-still-searches-the-ignored-directory – Paul Aug 28 '15 at 12:01
10

As BenC pointed out, Wildignore may not be the best way to ignore files if you are using CtrlP with an external search tool. Instead, you can use CtrlP's "custom_ignore" directive, as stated in their docs:

let g:ctrlp_custom_ignore = '\v[\/]\.(git|hg|svn)$'
let g:ctrlp_custom_ignore = {
    \ 'dir':  '\v[\/]\.(git|hg|svn)$',
    \ 'file': '\v\.(exe|so|dll)$',
    \ 'link': 'SOME_BAD_SYMBOLIC_LINKS',
    \ }
Jordan Eldredge
  • 1,587
  • 1
  • 19
  • 25
8

Because the title doesn't correspond to the best answer her is mine which corersponds not to ctrlp but to wildignore. Based on https://stackoverflow.com/a/579886/1170940

Vim will ignore file patterns specified in option wildignore , so you can set them like so:

:set wildignore=*.o,*~,*.pyc

For example, my wildignore looks as such

 set wildignore+=*/node_modules/*,_site,*/__pycache__/,*/venv/*,*/target/*,*/.vim$,\~$,*/.log,*/.aux,*/.cls,*/.aux,*/.bbl,*/.blg,*/.fls,*/.fdb*/,*/.toc,*/.out,*/.glo,*/.log,*/.ist,*/.fdb_latexmk

I use it for both ctrlp and NERDTree

pascalwhoop
  • 2,984
  • 3
  • 26
  • 40
5

See :help file-pattern. Basically if you just want to exclude anything that starts with a dot you can do .*.

Conner
  • 30,144
  • 8
  • 52
  • 73