Grep for String 并在对应行打开 [英] Grep for String and open at the corresponding line
问题描述
我在使用 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...
推荐答案
你可以在 Vim 的 quickfix 列表中加载你的 grep
输出:
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屋!