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

-cword stopped working

Open slashmili opened this issue 2 years ago • 11 comments

NVIM version: v0.6.1 vim-grepper version: 2b93535752ffcb312f9fab73d90e80dc9f2e60fc 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.

slashmili avatar May 08 '22 10:05 slashmili

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

dennishostetler avatar Feb 01 '23 23:02 dennishostetler

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

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

slashmili avatar Feb 06 '23 16:02 slashmili

Same issue here

LionelMartin avatar Mar 14 '23 19:03 LionelMartin

Same here

vext01 avatar Apr 12 '23 10:04 vext01

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

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 avatar Apr 12 '23 10:04 vext01

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

vext01 avatar Apr 18 '23 11:04 vext01

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?

lbonn avatar Apr 18 '23 12:04 lbonn

Do you by any chance run fish shell?

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

vext01 avatar Apr 18 '23 12:04 vext01

@vext01 there was this change in vim and neovim related to fish and escaping https://github.com/vim/vim/pull/8810, https://github.com/neovim/neovim/pull/15550

May be related to that

lbonn avatar Apr 18 '23 13:04 lbonn

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

dennishostetler avatar Apr 25 '23 20:04 dennishostetler

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

vext01 avatar May 26 '23 19:05 vext01