加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

在ctrlp vim中使用ag

发布时间:2020-12-15 19:11:33 所属栏目:安全 来源:网络整理
导读:我想使用ag(silver searcher)与ctrlp和vim。 我在.vimrc中有这个: if executable("ag") set grepprg=ag --nogroup --nocolor let g:ctrlp_user_command = 'ag %s -l --nocolor -g ""'endiflet g:ctrlp_show_hidden = 1set wildignore+=*/tmp/*,*.so,*.swp
我想使用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.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读