Vim的Ctrlp插件不能正确解析Ag(银色搜索)的--ignore选项

8

在命令行上使用ag时,例如:

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

我可以避免搜索我的node服务中超过一层深的任何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)--但这个选项似乎也会绕过wildignore。

哦!层次抽象的乐趣! - romainl
这是我第一次在问题中找到答案 ;) 我删除了 --ignore 部分,因为有 .agignore。我删除了 -U,以便 ag 仍然使用 .gitignore。我注意到 ag 默认忽略隐藏文件。 - tim-phillips
我已经在这里引用了这个页面:https://github.com/kien/ctrlp.vim/issues/174 - tim-phillips
1个回答

7

像您一样,我也同时使用这两种工具,但是我忽略文件夹的方式不同。

对于Ag,我使用.agignore文件,它具有与.gitignore相同的语法,并且可以放在您的主目录或项目文件夹中。

不确定这是否解决了您使用Ctrlp时遇到的问题,在任何情况下,对于我来说,它已经足够快了,因此我使用以下常规的忽略变量:

let g:ctrlp_custom_ignore = {
  \ 'dir':  '\v[\/](doc|tmp|node_modules)',
  \ 'file': '\v\.(exe|so|dll)$',
  \ }

4
Ag现在建议将文件命名为".ignore"而不是".agignore"。这样,其他工具如“ripgrep”也可以忽略相同的文件。 - Rory O'Kane
这是我找到的最完整的带有.agignore/.ignore的示例:https://github.com/kien/ctrlp.vim/issues/58#issuecomment-247017402 - gabe

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接