是否可以按照 grep -n 结果中的格式将文件打开到特定的行号?

And*_*ong 4 vim grep csh

我经常使用grep-n选项列表行号,

$ grep -n xyz .*
/ext1/acheong/foo/bar/a.cc:42:    inline bool abc(int xyz);
/ext1/acheong/foo/bar/a.cc:43:    inline bool def(int xyz);
/ext1/acheong/foo/bar/b.cc:415:            int xyz = result;
/ext1/acheong/foo/bar/b.cc:490:                xyz += result;
$
Run Code Online (Sandbox Code Playgroud)

是否有可能以vim这样的方式别名做

vim /ext1/acheong/foo/bar/b.cc:415
Run Code Online (Sandbox Code Playgroud)

会打开文件并自动查找第 415 行吗?

有可能csh吗?(是的,是的,csh带出恶魔和所有不圣洁的东西;但我别无选择……)其他贝壳的答案也很有用。

Dav*_*oye 7

好吧,它不是别名,您可以像这样使用 vim:

vim +<LineNumberHere> fileName

所以,例如

vim +150 .bash_history
Run Code Online (Sandbox Code Playgroud)

打开您的 .bash_history 文件(用于 bash),并导航到第 150 行。

顺便说一句,您也可以使用搜索词来执行此操作。例如

vim +/MyTerm MyFile
Run Code Online (Sandbox Code Playgroud)

打开 MyFile 并从顶部导航到第一次出现的 MyTerm。

享受!