是否可以在 Vim 中 grep 快速修复窗口? [英] Is it possible to grep the quickfix window in Vim?

查看:24
本文介绍了是否可以在 Vim 中 grep 快速修复窗口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我使用 ag.vim 插件在多个文件中搜索字符串 disabled.它会在 quickfix 窗口中返回一些结果:

Let’s say I use the ag.vim plugin to search for the string disabled through multiple files. It returns me some results in the quickfix window:

1 first_file.rb|1 col 1| disabled something something
2 second_file.rb|1 col 2| disabled another something

是否可以选择快速修复结果作为输入,通过它们进行 grep,并在新的快速修复窗口中打开结果?换句话说,如果我输入 :quickfix_grep first_file,新的 quickfix 只会弹出一个条目:

Is it possible to pick the quickfix results as an input, grep through them, and open results in new quickfix window? In other words, if I would enter :quickfix_grep first_file, new quickfix would pop up with only one entry:

1 first_file.rb|1 col 1| disabled something something

推荐答案

更新

为此需求编写了一个 vim 插件:https://github.com/sk1418/QFGrep

我对您的目标的理解是:

My understanding of your goal is:

您的快速修复中的 grep 结果在某种程度上很大,您想缩小范围你对它的看法.通过使用正则表达式输入命令,过滤 grep结果.过滤后的结果也应该显示在 QuickFix 中窗口,以便您可以打开/跳转到文件.

Your grep result is somehow huge in your quickfix, you want to narrow your view of it. by entering a command with regex, filter the grep result. The filtered result should also be displayed in QuickFix window, so that you could open/jump to the file.

如果以上是您想要的,请查看以下内容:

If the above is what you want, check out the following:

源这个函数和命令行:

function! GrepQuickFix(pat)
  let all = getqflist()
  for d in all
    if bufname(d['bufnr']) !~ a:pat && d['text'] !~ a:pat
        call remove(all, index(all,d))
    endif
  endfor
  call setqflist(all)
endfunction
command! -nargs=* GrepQF call GrepQuickFix(<q-args>)

然后在您的快速修复中的 grep/ack/whatever 显示内容之后,您可以输入

then after your grep/ack/whatever show stuffs in your quickfix, you could type

:GrepQF <regex>

在您的快速修复中进行过滤.

to do filtering in your quickfix.

这里我添加了一个 GIF 动画.我使用 Ack 而不是 grep,但这没有区别.给定的正则表达式将匹配文件名和 quickfix 中显示的文本.我做了两次过滤来证明这一点.

Here I add an GIF animation. I am using Ack instead of grep, but it makes no difference. The given regex will match filename and the text showing in quickfix. I did filtering twice to show that.

希望能帮到你.

这篇关于是否可以在 Vim 中 grep 快速修复窗口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆