Vim Ctrlp not parsing Ag (silver search) --ignore option correctly
Asked Answered
S

1

8

When using ag on the command line, like so:

$> ag . --ignore="*node_modules/*/node_modules" -l --nocolor -f -U -g ""

I am able to avoid searching through any node_modules directories more than one level deep in my node services, which is the desired behavior.

However, when I use the following in my vimrc, the node_modules directories more than one level deep are not ignored:

" Use The Silver Searcher https://github.com/ggreer/the_silver_searcher
if executable('ag')
  " Use Ag over Grep
  set grepprg=ag\ --nogroup\ --nocolor

  " Use ag in CtrlP for listing files. Lightning fast and respects .gitignore
  let g:ctrlp_user_command = 'ag %s --ignore="*node_modules/*/node_modules" -l --nocolor -f -U -g ""'
endif

How can I set up ag and ctrlp to correctly ignore those directories? Not sure if I need to use a different syntax (like regex) or some other gotcha when transplanting to vimrc.

The reason I'm not putting this in the wildignore is that node_modules are ignored in my .gitignore, so I'm using the -U option to ignore any vcs files (thereby allowing ag to search node_modules) -- but this option also seems to bypass the wildignore.

Stjohn answered 29/6, 2014 at 18:45 Comment(3)
Oh! The joys of layered abstractions!Psychochemical
This marks the first time I've found an answer inside a question ;) I removed the --ignore part due to .agignore. I removed -U so that ag would still use .gitignore. And I noticed that ag ignores hidden files by default.Di
I've reference this page here: github.com/kien/ctrlp.vim/issues/174Di
C
7

Like you I do use both tools, but the way I ignore folders is different

For Ag I use the .agignore file, it has the same sintax as .gitignore and just like it, it can go in your home folder or project folder.

Not sure if that will solve your problem with Ctrlp, in any case it is quite fast already for me so I use the normal ignore variable like this:

let g:ctrlp_custom_ignore = {
  \ 'dir':  '\v[\/](doc|tmp|node_modules)',
  \ 'file': '\v\.(exe|so|dll)$',
  \ }
Calmative answered 3/9, 2014 at 13:9 Comment(2)
Ag now recommends naming the file .ignore rather than .agignore. This allows other tools such as ripgrep to ignore the same files.Dodds
This was the most complete example I've found with the .agignore/.ignore github.com/kien/ctrlp.vim/issues/58#issuecomment-247017402Lunna

© 2022 - 2024 — McMap. All rights reserved.