junegunn / fzf.vim

fzf :heart: vim
MIT License
9.62k stars 584 forks source link

Add the option for Rg command to search the word under the cursor #1527

Closed PlasmaHH closed 7 months ago

PlasmaHH commented 7 months ago

For a long time now I have been using vim-ripgreps Rg command to search for stuff mostly because it provides one nice feature that is missing from fzf.vim Rg/RG commands: When started without parameters, it will use the word under the cursor.

For that to work probably plugin/fzf.vim command definition of Rg would have to call some special other function instead of shellescape that uses expand("") when is empty.

Really cool would be if additionally this could detect if a visual selection was being done and use that

(Btw. is there a reason why RG doesn't use shellescape?)

asheidan commented 7 months ago

Isn't it possible to do this already by including <C-r><C-w> (insert the word under the cursor) in your mapping?

Since I'm not sure how you invoke the command you might have to tweak this a little bit.

PlasmaHH commented 7 months ago

I usually dislike re-creating commands from plugins with my own changes as then when it updates in the plugin I will miss those changes usually... also thought that it might be intresting as a feature in general for others...

junegunn commented 7 months ago

No, what @asheidan is saying is that you can define your own mappings that do that in your Vim configuration file.

nnoremap <silent> <Leader>rg       :Rg <C-R><C-W><CR>
nnoremap <silent> <Leader>RG       :Rg <C-R><C-A><CR>
xnoremap <silent> <Leader>rg       y:Rg <C-R>"<CR>

You should be able to define similar commands that call :Rg in a similar fashion.

PlasmaHH commented 7 months ago

You should be able to define similar commands that call :Rg in a similar fashion. And my point was to add a feature to :Rg to use it as :Rg the way I have been from another plugin as I thought it would be useful for others too.