External grep and multiple matches on the same line
Hi!
It seems external grep tools like git grep, ack or ag only report the first match from the current line.The g pattern flag for :vimgrep can report multiple matches on the same line. But :vimgrep is slow.
Here's one solution I found that could be wrapped into a function or plugin:
:vimgrep /pattern/g `git grep --name-only pattern`
Is there a better way you can think of?
Thanks!
Posted Sep 17, 2014, 10:05 AM UTC
Let me introduce you to egrep, and extended regular expressions.
This will drop all empty lines and comments from a file and display to you just the things that matter.
You don't have to use egrep directly; you can just pass
-Eto grep itself. There are other examples in the man page.You could also try passing multiple
-ewhere each invocation specifies a pattern you want to match.grep can be symlinked to: egrep, fgrep, zgrep, zegrep, zfgrep to ack as different greps, you can also just pass the right argument to grep to get the behavior.
Pretty cool regex and commands!!
I want to navigate through every match from within vim using the quickfix window. I believe I can't do that easily with those grep commands. I'd like the behavior of vimgrep and the speed of git grep.
I don't follow. Is that egrep doing more than just saving some backslashes? I get the same behavior from:
Perhaps the -v is interfering with my understanding of your point. Can you give an example without it?
-v does a inverse match. It will display everything that does not match the regular expression passed.
Its very possible that 'grep' alone will do the same; as I mentioned egrep is basically a symlink to grep to cause it behave slightly different.
In my case; egrep may be overkill. Its just old-habits dieing hard. Growing up Solaris and realizing that things like 'grep' are not the same as 'gnu grep'.