mileszs / ack.vim

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

Search by a visual mode selection #171

Open AndrewRadev opened 8 years ago

AndrewRadev commented 8 years ago

This pull request enables the :Ack family of commands to work on visual selections. If the user marks an area of text and types :Ack, the contents of the visual selection will be used as a search term. The other two cases, an :Ack that uses the word under the cursor, and :Ack <term> which uses the given argument as a query, still work.

The text is given as-is, which means if there are special characters in there, the results might be unexpected (say, marking char* variable would consider the * a special character). Still, this has often been a useful shortcut for me, even if it does break down for more complicated expressions (sometimes, just one <cword> is not enough).

Note that this also fixes an issue I've (just) noticed with :AckWindow and, I thnk, :AckHelp -- if you use them without arguments, taking the word under the cursor, they don't work. That's because the helper functions concatenate the empty argument list with a list of files, so a:args is no longer empty and the code doesn't take the word under the cursor into account. If this PR is not accepted, I can make a separate pull request with just this fix. Incidentally, the reason I can't test :AckHelp properly is that I seem to have so many plugins that the combined resulting command-line is too long to process correctly :). But I can't think of a good fix to that.

I'd like to add a note to the documentation about the visual mode search, but I'm not sure where to do it. I think the documentation doesn't mention the "word under the cursor" functionality, so maybe we should add that somewhere as well?

I also have two additional features I'd like to propose, but it'll take me some time to prepare pull requests.

ches commented 8 years ago

Hi Andrew, thanks for this, and apologies for the very long delay for review.

This feature makes sense, despite the escaping gotcha there are a few of those that can come up with ack.vim anyway so I'd agree that it has enough practical utility as it is. I would like to review it separately from the bug fix though, if you don't mind—I think it's unfortunately clumsy, for instance, to have to pass the empty strings to work around the problem; there may not be a better easy alternative, but it'd be easier to consider and discuss in its own context.

So, if you could pull that out into a separate commit and open another PR, we can leave this one open and rebase it afterward. Thanks!

AndrewRadev commented 8 years ago

No worries, @ches, I know how hard it is to get around to fixing stuff in OS projects :)

I've created two extra PRs, #181 and #182 which fix this and another minor issue. Whenever we merge or close them, I can update this PR.

raine commented 5 years ago

Would be great to have.