r/vim•
inside_

Extending ag for vim

Hello vimmers,

I know many of you use external grep programs like ag, git grep or ack. ag --column can report the column number of the first match. But what about other matches on the line? AFAIK, none of the mentionned tools reports all matches on the line like :vimgrep /pattern/g can.

I would like to improve my grep workflow, so here's a fork of ag: https://github.com/inside/the_silver_searcher with the --vimgrep option added.

And here's an animated gif to show you what it does: http://i.imgur.com/dkbCuPr.gif

If you like this behavior, you can join the discussion on the github's pull request: https://github.com/ggreer/the_silver_searcher/pull/504

I hope you'll find this useful, Yann

Posted Sep 30, 2014, 11:57 AM UTC

5416
thebutcherer•

This is great! Well done!

My only comment would be on the option name. IMO "vimgrep" doesn't make much sense if you look at ag as a command line independent from vim. The suggestions that come to me though are sadly not great, they tend to be too long (e.g. "allmatchesonline"). Maybe "allmatches" or "exhaustive" would work.

But this is mostly a detail. I'd certainly use it when it's available!

3
inside_OP•

You made a point. I thought of --columns (notice the s). The reason I chose this name is that the --vimgrep option really formats the output for vim. I was inspired by the --ackmate option:

--ackmate: Output results in a format parseable by AckMate https://github.com/protocool/AckMate.

3
dddbbbFastFold made vim fast again•

Vim uses the 'g' flag for the same meaning (in :sub). This old sed man page says it stands for global (which is what I assumed for vim but the help isn't explicit).

How about --global?

2
tommcdocx•

I wanted to suggest this as well.

2
rdpate•

--all-line-matches, --line-multimatch? I like --columns, except it's much too close to --column. --all-columns?

1
Jaymuhz•

I'd call it vimmate then. It doesn't really make etymological sense, but OSS names never do.

0
metellius•

Why not just set grepprg to call ag --column and set grepformat to %f:%l:%c:%m? That's all I do, and it works fine without any patches. A bit weird that he already added --ackmate to be honest.

2
ismaelrivera•

The silver searcher (or Ack or grep) won't report the column of a second match on the same line, though, which is what that patch provides.

7
metellius•

Oh right. I missed that when reading the post.

1
denilsonsa•

If anyone prefers to watch the GIF as web video: http://www.gfycat.com/LimitedSaneHapuka

Alternatively, the OP might want to use https://asciinema.org/ to record the terminal.

2
SisRob•

I love asciinema, but it sucks that there's no kind of export...

1
denilsonsa•

Related: r/commandline/comments/2epn69/record_your_terminal/

1
mattn•

What is advantage against ag.vim? https://github.com/rking/ag.vim

1
inside_OP•

The advantage of ag --vimgrep over ag --column is reporting every match on the line. Ag.vim reads the ouput of ag and creates quickfix mappings for easy file opening.

2
inside_OP•

Thank you all for your interest!!

You are giving great feedback and I'd love to hear some more.

The option name need improvement, I agree with you. Feel free to comment at the github's pull request. I'm trying to get an answer from the ag author.

Regards

1
inside_OP•

I want to let you know that the --vimgrep option has been merged by ggreer to the master branch. You can give it a try by building Ag from the source.

Like ggreer said, it would be nice to split out some of these options. IMHO, good candidates are --line-per-match and --sep(arator) while keeping --vimgrep as an intuitive option.

Feedback is appreciated, Regards

1