gpt4 book ai didi

Vim:打开 Grep 给出的行上的匹配文件?

转载 作者:行者123 更新时间:2023-12-04 01:17:47 43 4
gpt4 key购买 nike

我想在命令行上 grepping 后自动到达 Vim 中结果的位置。有这样的功能吗?

要在 Vim 中按 grep 给出的行打开的文件:

% grep --colour -n checkWordInFile *
SearchToUser.java:170: public boolean checkWordInFile(String word, File file) {
SearchToUser.java~:17: public boolean checkWordInFile(String word, File file) {
SearchToUser.java~:41: if(checkWordInFile(word, f))

最佳答案

如果您通过管道将输出从 grep进入 vim

% grep -n checkWordInFile * | vim -

您可以将光标放在文件名上并点击 gF跳转到该文件中由该行 grep 输出引用的行。 ^WF将在新窗口中打开它。

在 vim 中你可以做同样的事情
:tabedit
:r !grep -n checkWordInFile *

这相当于但不如
:lgrep checkWordInFile *
:lopen

这会调出超棒的快速修复窗口,以便您可以方便地浏览搜索结果。

你也可以通过使用 vim 的原生 grep 来获得更慢但在某种程度上更灵活的结果:
:lvimgrep checkWordInFile *
:lopen

这个使用vim REs和路径(例如允许**)。运行可能需要 2-4 倍的时间(可能更多),但您可以使用花哨的 \(\)\@<= s 和羽毛的鸟。

关于Vim:打开 Grep 给出的行上的匹配文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2653419/

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