Grep for String并在相应的行处打开 [英] Grep for String and open at the corresponding line
本文介绍了Grep for String并在相应的行处打开的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在用grep
获得的几行中的多个文件中,有一个特定的字符串出现了几次.
I'm having several occurrences of a specific string over several files in several lines obtained with grep
.
$ grep -rn --include="*.cpp" mystring
lib/mlib/actionbuttonrule.cpp:300: mystring Foobar...
lib/mlib/actionbuttonrule.cpp:314: other mystring
lib/mlib/item.cpp:3025: /* mystring**/
lib/mlib/item.cpp:3082: mystring Foobar...
lib/mlib/item.cpp:3095: Foo mystring bar
我想在相应的行中依次打开这些文件.我尝试使用vim
进行此操作,但到目前为止,打开该行没有成功.
不能是vim
或grep
,但是我认为那里一定有某种功能...
I'd like to open these files sequencially on the corresponding lines. I tried to do it with vim
, but so far no success when it comes to open the line.
Mustn't be vim
or grep
, but I'd assume there must be some kind of functionality out there...
推荐答案
您可以使用以下方法将grep
输出加载到Vim的快速修复列表中:
You can load your grep
output in Vim's quickfix list with:
$ vim -q <(grep -rn --include="*.cpp" mystring)
使用:cn
转到下一个事件,使用:cp
转到上一个事件.
Go to the next occurence with :cn
and to the previous occurrence with :cp
.
请参见:help -q
和:help quickfix
.
这篇关于Grep for String并在相应的行处打开的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文