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

-cword stopped working #257

Open
slashmili opened this issue May 8, 2022 · 11 comments
Open

-cword stopped working #257

slashmili opened this issue May 8, 2022 · 11 comments

Comments

@slashmili
Copy link

NVIM version: v0.6.1
vim-grepper version: 2b93535
OS: Mac 12.3.1
git: 2.33.0

I've been using this option for a while but I've noticed it's stopped working recently:

noremap <c-g> :Grepper -cword -noprompt<CR>

If run this command Grepper -cword, I get:

git grep -nGI> '\\bnoremap\\b'

When I press enter, it won't match with any record

If run it again and this time, remove one set of \ like this:

git grep -nGI> '\bnoremap\b'

it finds all the matches.

@dennishostetler
Copy link

Same issue here on my mac. It works on Windows though.

@slashmili
Copy link
Author

slashmili commented Feb 6, 2023

just for the record I ended up using this for now:

noremap <c-g> :execute "Grepper -noprompt -query " . expand("<cword>")<CR>

@LionelMartin
Copy link

Same issue here

@vext01
Copy link

vext01 commented Apr 12, 2023

Same here

@vext01
Copy link

vext01 commented Apr 12, 2023

noremap :execute "Grepper -noprompt -query " . expand("")

Does anyone have a version of this I can drop in my init.lua?

I thought this might work, but no:

vim.api.nvim_set_keymap('n', 'gs', ':Grepper -noprompt -query ' .. vim.fn.expand('<cword>') .. '<CR>', { noremap = true, silent = true })

EDIT:

This works:

vim.api.nvim_set_keymap('n', 'gs', ':execute ":Grepper -noprompt -query " .. shellescape(expand("<cword>"))<cr>', { noremap = true, silent = true })

@vext01
Copy link

vext01 commented Apr 18, 2023

I had a prod around in the plugin sources today. There's a call to shellescape that is double escaping the word anchors.

As @slashmili noted, this means we end up running commands like:

git grep -nGI> '\\bnoremap\\b'

instead of:

git grep -nGI> '\bnoremap\b'

This diff seems to work, but I can't vouch for its correctness. I'm not good at lua or vimscript:

diff --git a/plugin/grepper.vim b/plugin/grepper.vim
index 3552d51..9cd10e0 100644
--- a/plugin/grepper.vim
+++ b/plugin/grepper.vim
@@ -401,7 +401,7 @@ function! s:escape_cword(flags, cword)
   endif
   let a:flags.query_orig = a:cword
   let a:flags.query_escaped = 1
-  return shellescape(escaped_cword)
+  return "'" . escaped_cword . "'"
 endfunction
 
 " s:compute_working_directory() {{{2

@lbonn
Copy link
Collaborator

lbonn commented Apr 18, 2023

shellescape is here for a reason, so that the search string is correctly forwarded to the grep program if a special character is in the query.

It is working fine on linux with bash afaik, question would be why the \ is doubled on Mac in this case. Do you by any chance run fish shell?

@vext01
Copy link

vext01 commented Apr 18, 2023

Do you by any chance run fish shell?

You gotta be kidding me! I'm using fish on OpenBSD and Linux!

@lbonn
Copy link
Collaborator

lbonn commented Apr 18, 2023

@vext01 there was this change in vim and neovim related to fish and escaping vim/vim#8810, neovim/neovim#15550

May be related to that

@dennishostetler
Copy link

I use the fish shell on my mac. Seems like you're on to something.

@vext01
Copy link

vext01 commented May 26, 2023

I've just tried with my shell set to ksh and there is no issue there. Seems to be to do with fish...

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

No branches or pull requests

5 participants