rking / ag.vim

Vim plugin for the_silver_searcher, 'ag', a replacement for the Perl module / CLI script 'ack'
1.74k stars 131 forks source link

Fix long line matches #102

Closed Numkil closed 9 years ago

Numkil commented 9 years ago

This pull requests resolve problem #95.

I ask ag to only display the match and nothing else of the string. Then I construct a regex allowing up to 50 characters before and 50 characters behind to be included in the matching result.

Let me know what you think. :)

Numkil commented 9 years ago

I just noticed that -o and --vimgrep do not work together, the -o switch is ignored. I will contact the_silver_searcher about this.

losingkeys commented 9 years ago

Great idea! Unfortunately I'm having some issues with the branch. When I search my dotfiles for set, it says "no matches", but when I switch back to the master branch, it shows matches (some with annoyingly long lines).

Another thought: will this work for all window sizes? I think it'll still wrap for some windows, which might be ok (because it probably won't wrap that many times), but it'd be nice to get it exact too.

50e30ae is a duplicate from #100 (merged). I can just cherry-pick the other commit when it's ready, or you can rebase the pull, whichever you prefer.

This is another pull that would benefit from tests, gotta be careful when adding regexes to others' search strings :smile:.

iazel commented 9 years ago

You should notice that grepargs isn't always the regexp, but could include other options, e.g. I usually include a filetypes restriction, so the result would be something like .\{0,50}--ft myregexp.\{0,50}. This also happen if you want to search in a subdir only. I bet @losingkeys has done at least one of these, and that's cause the no-match. Remember also the -Q flag will disable the regexp engine and consider it as simple text, much faster to match, so even if the pattern could be guessed, it's still a bad idea to alter it.

I think the -o flag is enough and to not include it by default, let the user decide when he need it or not (like every other options), plus it's not widely supported (like --vimgrep).

Maybe a good idea to mitigate the problem could be setl nowrap in the quickfix window

losingkeys commented 9 years ago

Ohh, I didn't think of that. Good catch @lazel. My current g:ag_prg is ag --vimgrep --smartcase. It should probably handle other ag options too, like --literal.

On Sun, May 17, 2015 at 6:43 PM, Iazel notifications@github.com wrote:

You should notice that grepargs isn't always the regexp, but could include other options, e.g. I usually include a filetypes restriction, so the result would be something like .{0,50}--ft myregexp.{0,50}. This also happen if you want to search in a subdir only. I bet @losingkeys https://github.com/losingkeys has done at least one of these, and that's cause the no-match.

I think the -o flag is enough and to not include it by default, let the user decide when he need it or not (like every other options), plus it's not widely supported (same situation of --vimgrep).

— Reply to this email directly or view it on GitHub https://github.com/rking/ag.vim/pull/102#issuecomment-102870872.

Numkil commented 9 years ago

Yeah those are some good points, which I didn't think about. And you are right that's I'm sure why it doesn't work for @losingkeys. I had just made this quickly as a proof that it might work, but apparently it doesn't even because -o and --vimgrep don't work together, which is a limitation in ag itself. Maybe just setting nowrap as @Iazel suggested is the only way to go even if it's not perfect.