Given the result of grep -n, how can I open vim in that specific line? (using only keyboard)
up vote
3
down vote
favorite
When I run grep "keyword" -n
and get the following list of results:
a/b/c:10: keyword
a/b/c:70: keyword
a/b/d:50: keyword
How can I open one of the files (say the 2nd in list) in the line it found?
I now just copy the the output using my mouse, and copy it after vim
and then add +
with the line number I copy. (meaning I write vim a/b/c +70
using the mouse copy to get the file name, and another mouse copy to get the line number [or I just copy it by hand, when its short enough])
Is there a way to do it with a keyboard shortcut?
command-line vim grep
add a comment |
up vote
3
down vote
favorite
When I run grep "keyword" -n
and get the following list of results:
a/b/c:10: keyword
a/b/c:70: keyword
a/b/d:50: keyword
How can I open one of the files (say the 2nd in list) in the line it found?
I now just copy the the output using my mouse, and copy it after vim
and then add +
with the line number I copy. (meaning I write vim a/b/c +70
using the mouse copy to get the file name, and another mouse copy to get the line number [or I just copy it by hand, when its short enough])
Is there a way to do it with a keyboard shortcut?
command-line vim grep
You can try something like that:echo a/b/c:70: keyword | awk '{print $1}' | sed 's,:$,,' | sed 's,:, +,' | xargs vim && reset
.
– Arkadiusz Drabczyk
2 hours ago
2
Also, if you're interested in using Vim more efficiently, do check out the dedicated Vi and Vim Stack Exchange site.
– muru
2 hours ago
add a comment |
up vote
3
down vote
favorite
up vote
3
down vote
favorite
When I run grep "keyword" -n
and get the following list of results:
a/b/c:10: keyword
a/b/c:70: keyword
a/b/d:50: keyword
How can I open one of the files (say the 2nd in list) in the line it found?
I now just copy the the output using my mouse, and copy it after vim
and then add +
with the line number I copy. (meaning I write vim a/b/c +70
using the mouse copy to get the file name, and another mouse copy to get the line number [or I just copy it by hand, when its short enough])
Is there a way to do it with a keyboard shortcut?
command-line vim grep
When I run grep "keyword" -n
and get the following list of results:
a/b/c:10: keyword
a/b/c:70: keyword
a/b/d:50: keyword
How can I open one of the files (say the 2nd in list) in the line it found?
I now just copy the the output using my mouse, and copy it after vim
and then add +
with the line number I copy. (meaning I write vim a/b/c +70
using the mouse copy to get the file name, and another mouse copy to get the line number [or I just copy it by hand, when its short enough])
Is there a way to do it with a keyboard shortcut?
command-line vim grep
command-line vim grep
edited 1 hour ago
muru
135k19288488
135k19288488
asked 3 hours ago
CIsForCookies
1938
1938
You can try something like that:echo a/b/c:70: keyword | awk '{print $1}' | sed 's,:$,,' | sed 's,:, +,' | xargs vim && reset
.
– Arkadiusz Drabczyk
2 hours ago
2
Also, if you're interested in using Vim more efficiently, do check out the dedicated Vi and Vim Stack Exchange site.
– muru
2 hours ago
add a comment |
You can try something like that:echo a/b/c:70: keyword | awk '{print $1}' | sed 's,:$,,' | sed 's,:, +,' | xargs vim && reset
.
– Arkadiusz Drabczyk
2 hours ago
2
Also, if you're interested in using Vim more efficiently, do check out the dedicated Vi and Vim Stack Exchange site.
– muru
2 hours ago
You can try something like that:
echo a/b/c:70: keyword | awk '{print $1}' | sed 's,:$,,' | sed 's,:, +,' | xargs vim && reset
.– Arkadiusz Drabczyk
2 hours ago
You can try something like that:
echo a/b/c:70: keyword | awk '{print $1}' | sed 's,:$,,' | sed 's,:, +,' | xargs vim && reset
.– Arkadiusz Drabczyk
2 hours ago
2
2
Also, if you're interested in using Vim more efficiently, do check out the dedicated Vi and Vim Stack Exchange site.
– muru
2 hours ago
Also, if you're interested in using Vim more efficiently, do check out the dedicated Vi and Vim Stack Exchange site.
– muru
2 hours ago
add a comment |
1 Answer
1
active
oldest
votes
up vote
5
down vote
accepted
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
Trying to use the same method on git status, to no avail :( - vim -q <(git status | grep modified)
– CIsForCookies
2 hours ago
2
@CIsForCookies That won't be in the same format asgrep -n
(<filename>:<line>: ...
). I use the fugitive plugin for Git, and then it's a matter of:Gstatus
, move to desired file and press Enter.
– muru
1 hour ago
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
5
down vote
accepted
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
Trying to use the same method on git status, to no avail :( - vim -q <(git status | grep modified)
– CIsForCookies
2 hours ago
2
@CIsForCookies That won't be in the same format asgrep -n
(<filename>:<line>: ...
). I use the fugitive plugin for Git, and then it's a matter of:Gstatus
, move to desired file and press Enter.
– muru
1 hour ago
add a comment |
up vote
5
down vote
accepted
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
Trying to use the same method on git status, to no avail :( - vim -q <(git status | grep modified)
– CIsForCookies
2 hours ago
2
@CIsForCookies That won't be in the same format asgrep -n
(<filename>:<line>: ...
). I use the fugitive plugin for Git, and then it's a matter of:Gstatus
, move to desired file and press Enter.
– muru
1 hour ago
add a comment |
up vote
5
down vote
accepted
up vote
5
down vote
accepted
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
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
answered 2 hours ago
muru
135k19288488
135k19288488
Trying to use the same method on git status, to no avail :( - vim -q <(git status | grep modified)
– CIsForCookies
2 hours ago
2
@CIsForCookies That won't be in the same format asgrep -n
(<filename>:<line>: ...
). I use the fugitive plugin for Git, and then it's a matter of:Gstatus
, move to desired file and press Enter.
– muru
1 hour ago
add a comment |
Trying to use the same method on git status, to no avail :( - vim -q <(git status | grep modified)
– CIsForCookies
2 hours ago
2
@CIsForCookies That won't be in the same format asgrep -n
(<filename>:<line>: ...
). I use the fugitive plugin for Git, and then it's a matter of:Gstatus
, move to desired file and press Enter.
– muru
1 hour ago
Trying to use the same method on git status, to no avail :( - vim -q <(git status | grep modified)
– CIsForCookies
2 hours ago
Trying to use the same method on git status, to no avail :( - vim -q <(git status | grep modified)
– CIsForCookies
2 hours ago
2
2
@CIsForCookies That won't be in the same format as
grep -n
(<filename>:<line>: ...
). I use the fugitive plugin for Git, and then it's a matter of :Gstatus
, move to desired file and press Enter.– muru
1 hour ago
@CIsForCookies That won't be in the same format as
grep -n
(<filename>:<line>: ...
). I use the fugitive plugin for Git, and then it's a matter of :Gstatus
, move to desired file and press Enter.– muru
1 hour ago
add a comment |
Thanks for contributing an answer to Ask Ubuntu!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1100032%2fgiven-the-result-of-grep-n-how-can-i-open-vim-in-that-specific-line-using-on%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
You can try something like that:
echo a/b/c:70: keyword | awk '{print $1}' | sed 's,:$,,' | sed 's,:, +,' | xargs vim && reset
.– Arkadiusz Drabczyk
2 hours ago
2
Also, if you're interested in using Vim more efficiently, do check out the dedicated Vi and Vim Stack Exchange site.
– muru
2 hours ago