I want to use ag (silver searcher) with ctrlp and vim. I have this in my .vimrc:
if executable("ag")
set grepprg=ag\ --nogroup\ --nocolor
let g:ctrlp_user_command = 'ag %s -l --nocolor -g ""'
endif
let g:ctrlp_show_hidden = 1
set wildignore+=*/tmp/*,*.so,*.swp,*.zip,*/.tmp/*,*/.sass-cache/*,*/node_modules/*,*.keep,*.DS_Store,*/.git/*
I want ctrlp to include hidden files but those are hidden. If I add -u
to the ag command it shows all hidden files but doesn't respect the wildignore or .gitignore. Is it possible to make it respect these?
If you are using a custom finder via
ctrlp_user_command
several options, includingctrlp_show_hidden
ctrlp_custom_ignore
and vim'swildignore
patterns, are not used by CtrlP (see documentation).So you are left at the mercy of your searching tool, in this case, ag. Fortunately you can do a couple things that should give you the behavior you want.
To get your hidden dotfiles to appear, but still respect
ignore
files, use the--hidden
option for ag:let g:ctrlp_user_command = 'ag %s -l --nocolor --hidden -g ""'
Now for defining patterns to ignore, you can use ag's own ignore file .agignore. This can be a per directory or a global one that ag will check on each run. You place that in your home dir
~/.agignore
.I understand it can be nice to have vims
wildignore
take care of patterns, but with.agignore
you get the bonus of those restrictions when using ag from the cli. If you want to search all files just use theag -u
command you mentioned to bypass anyignore
files.As a final tidbit, there is a Dictionary format you can use to define
g:ctrlp_user_command
which contains anignore
key that will make CtrlP usewildignore
patterns. However, I've never tried this and the documentation points out a potential performance hit. You might try this method if you don't like my other proposed solution (see documentation).