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.

user1797466
  • 507
  • 6
  • 14
  • Oh! The joys of layered abstractions! – romainl Jun 29 '14 at 19:26
  • 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. – tim-phillips May 12 '16 at 19:39
  • I've reference this page here: https://github.com/kien/ctrlp.vim/issues/174 – tim-phillips May 12 '16 at 19:52

1 Answers1

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)$',
  \ }
SystematicFrank
  • 16,555
  • 7
  • 56
  • 102
  • 4
    Ag [now recommends](https://github.com/ggreer/the_silver_searcher/commit/dd8e8396efc6f6be6ef3a730e700d6ef8da1d813) naming the file `.ignore` rather than `.agignore`. This allows other tools such as [`ripgrep`](https://github.com/BurntSushi/ripgrep) to ignore the same files. – Rory O'Kane Nov 21 '16 at 19:25
  • This was the most complete example I've found with the `.agignore`/`.ignore` https://github.com/kien/ctrlp.vim/issues/58#issuecomment-247017402 – gabe Jul 19 '19 at 16:51