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_commandseveral options, includingctrlp_show_hiddenctrlp_custom_ignoreand vim'swildignorepatterns, 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
ignorefiles, use the--hiddenoption 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
wildignoretake care of patterns, but with.agignoreyou get the bonus of those restrictions when using ag from the cli. If you want to search all files just use theag -ucommand you mentioned to bypass anyignorefiles.As a final tidbit, there is a Dictionary format you can use to define
g:ctrlp_user_commandwhich contains anignorekey that will make CtrlP usewildignorepatterns. 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).