在ctrlp vim中使用ag

我想使用ag(silver searcher)与ctrlp和vim。
我在.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/*

我想要ctrlp包含隐藏的文件,但这些被隐藏。如果我将-u添加到ag命令中,它会显示所有隐藏文件,但不遵守wildignore或.gitignore。有可能让它尊重这些吗?

如果您通过ctrlp_user_command使用自定义查找器,则会出现几个选项,包括ctrlp_show_hidden ctrlp_custom_ignore和vim的wildignore模式,不会被CtrlP( see documentation)使用。

g:ctrlp_show_hidden

Note: does not apply when a command defined with
|g:ctrlp_user_command| is being used.

g:ctrlp_custom_ignore

Note #1: by default,|wildignore| and |g:ctrlp_custom_ignore| only
apply when |globpath()| is used to scan for files,thus these options
do not apply when a command defined with |g:ctrlp_user_command| is
being used.

所以你被遗弃在你的搜索工具的怜悯,在这种情况下,ag。幸运的是,你可以做几件事情,给你你想要的行为。

为了让你隐藏的dotfiles出现,但仍然尊重忽略文件,请使用–hidden选项为ag:

让g:ctrlp_user_command =’ag%s -l –nocolor –hidden -g“”’

现在要定义要忽略的模式,您可以使用ag自己的忽略文件.agignore.这可以是每个目录或全局的,每个运行将检查。你把它放在你家的目录里〜/ .agignore。

我知道拥有野蛮人照顾模式可能很好,但是使用.agignore,当使用来自cli的ag时,您可以获得这些限制的奖金。如果要搜索所有文件,只需使用您提到的ag -u命令绕过任何忽略文件

作为最后的tidbit,您可以使用Dictionary格式来定义g:ctrlp_user_command,其中包含一个忽略键,这将使CtrlP使用wildignore模式。然而,我从来没有尝试过这个文档,并指出了潜在的性能影响。如果您不喜欢我的其他提议的解决方案(see documentation),您可以尝试此方法

Note #3: unless the |Dictionary| format is used and ‘ignore’ is defined and set to 1,the |wildignore| and |g:ctrlp_custom_ignore| options do not apply when these custom commands are being used. When not present,‘ignore’ is set to 0 by default to retain the performance advantage of using external commands.

相关文章

解决方案:解决linux下vim乱码的情况:(修改vimrc的内容)全...
Linuxvi/vim所有的UnixLike系统都会内建vi文书编辑器,其他的...
      vim正则匹配:空行:/^$/  /^[\t]*$/注释...
$select-editorSelectaneditor.Tochangelater,run'sele...
上次手贱忘了保存,这次就简单做个备忘吧,把踩过的坑记一下...
Linux之文本编译器小结vim的优势所有的UNIX-LIKE习通都会内置...