The silver searcherer has --column
option that works like this:
% ag silver --column
Brewfile
40:13:install the_silver_searcher
where 13 denotes the column where the match (silver) begins.
Is there a way to get something similar with git-grep
?
EDIT
The reason for this is that I want to use git-grep
as a grepprg
in vim (much faster in certain cirumstances e.g. node.js project).
With Git 2.19 (Q3 2018), "git grep
" learned the "--column
" option that gives not just the line number but the column number of the hit.
See commit 240cf2a, commit 6653fec, commit a449f27, commit 89252cd, commit 017c0fc, commit 68d686e (22 Jun 2018), and commit f8a0c6e (20 Jun 2018) by Taylor Blau (ttaylorr
).
(Merged by Junio C Hamano -- gitster
-- in commit d036d66, 18 Jul 2018)
builtin/grep.c
: add '--column
' option to 'git-grep(1)
'Teach '
git-grep(1)
' a new option, '--column
', to show the column number of the first match on a non-context line.
This makes it possible to teach 'contrib/git-jump/git-jump
' how to seek to the first matching position of a grep match in your editor, and allows similar additional scripting capabilities.For example:
$ git grep -n --column foo | head -n3 .clang-format:51:14:# myFunction(foo, bar, baz); .clang-format:64:7:# int foo(); .clang-format:75:8:# void foo()
So:
when running '
git jump grep
', column numbers will also be emitted, e.g.git jump grep "hello"
would return:----------------------------------- foo.c:2:9: printf("hello word!\n"); -----------------------------------
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With