Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Search by a visual mode selection #171

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

AndrewRadev
Copy link

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
Copy link
Collaborator

ches commented Apr 5, 2016

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
Copy link
Author

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
Copy link

raine commented Apr 30, 2019

Would be great to have.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants