是否可以grep Vim中的quickfix窗口? [英] Is it possible to grep the quickfix window in Vim?

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

问题描述

假设我使用ag.vim插件通过多个文件搜索字符串disabled.它在快速修复窗口中返回一些结果:

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

是否可以将quickfix结果作为输入,通过它们进行grep,然后在新的quickfix窗口中打开结果?换句话说,如果我输入: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结果在您的quickfix中有些巨大,您想缩小 您对此的看法.通过使用正则表达式输入命令,过滤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/无论在Quickfix中显示什么内容之后,您都可以输入

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.

希望有帮助.

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

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