mileszs / ack.vim

Vim plugin for the Perl module / CLI script 'ack'
Other
3.08k stars 396 forks source link

Highlight should use <> wrappers when -w is used #185

Open osa1 opened 8 years ago

osa1 commented 8 years ago

Hi all,

Thanks for the amazing plugin. This has been invaluable since I discovered ag years ago.

Anyway, one small annoyance is that I use :Ack! -w a lot. The problem is that ack.vim's highlighter does not work well with that command because it highlights more that it should, because it doesn't wrap the word with <> before populating the highlight buffer (or whatever that's called, the let @/ = ... line).

Would that be possible to improve this so that when I use :Ack! -w I only get complete words highlighted?

(It may be really hard to make vim's word highlighter to completely match with ack/ag's word pattern, but it'd be a good enough solution if we could just wrap the word to highlight with <> I think)

ches commented 8 years ago

Hi,

I've not really used the -w feature much and I'm not sure I understand the shortcoming you're describing—based on the subject line and your reference to <> I think I follow you, but perhaps a screenshot would help.

Assuming I have understood, you could try introducing a conditional in the s:Highlight function to improve the handling in the case that the args contain -w. It's a bit hacky but given that a.) this part of the implementation is already kinda hacky, and b.) both ack and ag support -w with the same meaning (and it comes from grep even), I'd consider a pull request for it. Even better if there's a way to avoid breaking other potential ackprg configurations that might not support -w, without it becoming too much of a mess.

It might also be possible to support the highlighting in a completely different way than the current approach that might account for your wish more easily and also perhaps fix #175 at the same time. I'm not sure, I've never really looked closely at the possibilities.