vim-easygrep icon indicating copy to clipboard operation
vim-easygrep copied to clipboard

Allow dynamic search directory and search mode

Open kminh opened this issue 9 years ago • 2 comments

First of all, thank you for such a nice plugin, it's probably the best grep plugin for Vim out there.

I want to ask if there's a way to dynamically set the search directory and search mode when doing a single search, without having to use the \vo or \vy mapping. I mean can we have new commands, maybe:

Grep [pattern] [directory] # if [directory] is set here it overrides the EasyGrepRoot setting
GrepBuffers # do the same thing as Grep but using the Buffer search mode

The ability to prompt for [directory] when using \vv (in normal mode or visual mode) is great too.

It is also useful to be able to define custom mappings that change options AND do a grep, for example:

map <silent> <Leader>vb <plug>EgMapGrepCurrentWordBufferMode_v

This allows us to quickly search for text under cursor in loaded buffers, without having to manually change the option, and then type the key combination.

kminh avatar Nov 13 '15 22:11 kminh

I'm glad you find the plugin useful!

Great ideas. I think that the first thought about a specific directory could be accomplished by adding a command line switch; e.g. Grep -d [directory]. Implementing it should be mostly straightforward.

For the GrepBuffers command, perhaps a command line switch 'Grep -b' would serve that purpose as well? In general I don't really like having separate commands because it limits the composability by requiring an outer-product of commands to achieve all possible options that you might want to invoke. Long term I actually would like to try to implement all mappings to actually be an invocation of a ":Grep" command with the appropriate options. I think that would allow achieving all existing mappings and many more.

I like these ideas and I'll see about adding some support for these features in the next version.

dkprice avatar Nov 19 '15 03:11 dkprice

Thank you for your consideration.

In my opinion it's all about consistency. Since grep, ack, and ag all use the grep [pattern] [directory] structure, -d option might seem inconsistent.

However, I'm fine with -b and -d options, because I will map some of my keys to those commands anyway :)

As for dynamic option changing, instead of having a mapping for each option, perhaps we should map <leader>vg to switch to command mode with pattern pre-escaped from word under cursor/visually selected, from there user can simply complete the command as needed.

kminh avatar Nov 19 '15 05:11 kminh