ggreer/the_silver_searcher — pull request #504 by inside (2014-09-29 10:02:29+00:00)
Title: --vimgrep option added, reporting every match on the line

Output results like vim's :vimgrep /pattern/g would (it reports every match on the line).
Here's a ~/.vimrc configuration example:

set grepprg=ag\ --vimgrep\ $*
set grepformat=%f:%l:%c:%m

Then use :grep to grep for something.
Then use :copen :cn :cp etc.. to navigate through the matches.

Ag is a good candidate for vim users as an external grepping tool because of its speed and its --column options to get the cursor on the first matching pattern.

But what about reporting every match on the line? The --vimgrep option does that. The matches navigation isn't approximate anymore and matches are easy to locate with :cn and :cp.

Here's an example of the --vimgrep output for a file containing:

foo bar baz
bar foo baz foo
bar baz

% ag --vimgrep foo /tmp/a.txt
/tmp/a.txt:1:1:foo bar baz
/tmp/a.txt:2:5:bar foo baz foo
/tmp/a.txt:2:13:bar foo baz foo

The format is:

"file":"line number":"column number":"line content"

Grepping tools I know (git grep, ack-grep) don't support this output. I think Ag would be the first, making it more and more efficient.

Let me know what you think.

Regards,
Yann