8

ag在命令行上使用时,如下所示:

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

我能够避免在我的节点服务中搜索超过一层的任何 node_modules 目录,这是所需的行为。

但是,当我在 vimrc 中使用以下内容时,不会忽略超过一级深度的 node_modules 目录:

" 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

如何设置agctrlp正确忽略这些目录?不确定在移植到 vimrc 时是否需要使用不同的语法(如正则表达式)或其他一些问题。

我没有把它放在 wildignore 中的原因是 node_modules 在我的 .gitignore 中被忽略了,所以我使用-U忽略任何 vcs 文件的选项(从而允许ag搜索 node_modules)——但这个选项似乎也绕过了野蛮的。

4

1 回答 1

7

像你一样,我确实使用这两种工具,但我忽略文件夹的方式不同

对于Ag ,我使用该.agignore文件,它与它具有相同的 sintax,.gitignore并且就像它一样,它可以放在您的主文件夹或项目文件夹中。

不确定这是否会解决您的问题Ctrlp,无论如何它对我来说已经相当快了,所以我使用正常的忽略变量,如下所示:

let g:ctrlp_custom_ignore = {
  \ 'dir':  '\v[\/](doc|tmp|node_modules)',
  \ 'file': '\v\.(exe|so|dll)$',
  \ }
于 2014-09-03T13:09:21.360 回答