Given the result of grep -n, how can I open vim in that specific line? (using only keyboard)
Two things:
-
Vim has some support for
grep
.If you open Vim, and do
:grep keyword ...
, Vim populates the quickfix list with the results, and jumps to the first file. You can then jump to the nth quickfix entry with:cc n
(and other commands). -
You can populate the aforementioned quickfix list using grep's output:
vim -q <(grep -n keyword ...)
And then use the quickfix navigation commands mentioned above.
Either is simpler than playing around with grep's output manually.
As an alternative to (2), you can save grep's output to a file and use that file instead, if you think you won't necessarily open Vim after:
grep ... | tee log
vim -q log
You could make is so if there were not support for grep already as @muru answered:
:cexpr system("grep -n keyword")
It can be used with another command, git grep
for example.
Also, you can open the output in a buffer and use "cbuffer" on it.
See quickfix section from the manual about it.