gpt4 book ai didi

vim - 使用 Vim 链接 vimgrep 和 copen

转载 作者:行者123 更新时间:2023-12-02 20:47:01 25 4
gpt4 key购买 nike

当我必须在某些目录中递归搜索模式时,我会这样做:

:vimgrep 'some-pattern' app/views/**

然后,我必须输入:

:copen 20

这样我终于可以在 quikfix 窗口中看到包含“some-pattern”的文件列表了 20 行。

它完全符合我的需求,但是有什么方法可以链接这两个命令,所以每次我请求 vimgrep 时,如果我输入“:copen 20”,它就会将结果“通过管道”发送到快速修复窗口?

尽可能地,我更愿意坚持标准的东西(任何基于 .vimrc 的方法?),并避免使用插件在文件中查找。

我一周前才转向 Vim,谢谢你的帮助。

最佳答案

您可以将此代码段添加到您的 vimrc 中:

" create a self-clearing autocommand group called 'qf'
augroup qf
" clear all autocommands in this group
autocmd!

" do :cwindow if the quickfix command doesn't start
" with a 'l' (:grep, :make, etc.)
autocmd QuickFixCmdPost [^l]* cwindow

" do :lwindow if the quickfix command starts with
" a 'l' (:lgrep, :lmake, etc.)
autocmd QuickFixCmdPost l* lwindow

" do :cwindow when Vim was started with the '-q' flag
autocmd VimEnter * cwindow
augroup END

每当您执行 :vimgrep 或填充快速修复/位置列表的其他命令并且存在合格匹配项时,这都会自动打开快速修复/位置窗口。

示例:

:vim foo **/*.js
:lgrep bar *.rb
$ vim -q <(grep baz test.txt)

请参阅 :help autocmd:help :cwindow

关于vim - 使用 Vim 链接 vimgrep 和 copen,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43953589/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com