junegunn / fzf.vim

fzf :heart: vim
MIT License
9.59k stars 582 forks source link

Is there a way to forbid fzf reload action not quote the {q} template ? #1369

Closed Napoleon-Jm closed 2 years ago

Napoleon-Jm commented 2 years ago

When I use the 'Advanced ripgrep integration', I changed the initial_command not shellescape the query, in case I can use opts for rg command.

let initial_command = printf(command_fmt, shellescape(a:query)) to let initial_command = printf(command_fmt,a:query) and remove the last --.

The :RG -w foo, work's fine, btw, the preview reload will quote the {q}, so when query changed in preivew, the reload will false to rg --<some initial flag> '-w foo'.

So I want to know could be supported some args to forbid the quote action when replace the {q} template.

The fzf template replace source code I found: https://github.com/junegunn/fzf/blob/cd2340141100e057005d31e653c0ce7a0f7a4af7/src/terminal.go#L1708

By the way, since it's a 'advanced integration', the user may be know the rg rule, maybe remove the quote action?

junegunn commented 2 years ago

I think you can use eval like this:

fzf --disabled --bind 'change:reload:eval "ls "{q}'
  # and type in something like "-al /"

since it's a 'advanced integration'

Advanced fzf, not advanced Ripgrep :)

Napoleon-Jm commented 2 years ago

I think you can use eval like this:

fzf --disabled --bind 'change:reload:eval "ls "{q}'
  # and type in something like "-al /"

since it's a 'advanced integration'

Advanced fzf, not advanced Ripgrep :)

Changed like this?

function! RipgrepFzf(query, fullscreen)
  let command_fmt = 'rg --column --line-number --no-heading --color=always --smart-case %s || true'
  let initial_command = printf(command_fmt, a:query)
  let reload_command = printf(command_fmt, ':eval "ls "{q}')
  let spec = {'options': ['--phony', '--query', a:query, '--bind', 'change:reload:'.reload_command]}
  call fzf#vim#grep(initial_command, 1, fzf#vim#with_preview(spec), a:fullscreen)
endfunction

command! -nargs=* -bang RG call RipgrepFzf(<q-args>, <bang>0)

It's not work, and I used wrong case, I guess, fresh for fzf, forgive me.... @junegunn

mattijons commented 2 years ago

This works for me

function! RipgrepFzf(query, fullscreen)
  let command_fmt = 'rg --column --line-number --no-heading --color=always --smart-case '
  let initial_command = command_fmt.(a:query)
  let reload_command = printf(command_fmt.('%s'), '{q}')
  let spec = {'options': ['--phony', '--query', a:query, '--bind', 'change:reload:eval '.reload_command]}
  call fzf#vim#grep(initial_command, 1, fzf#vim#with_preview(spec), a:fullscreen)
endfunction

command! -nargs=* -bang RG call RipgrepFzf(<q-args>, <bang>0)
basilgood commented 2 years ago

For a normal :RG<cr> (live grep) not :RG -w 'foo'<cr> this works for me:

function! RipgrepFzf(query, fullscreen)
  let command_fmt = 'rg --column --line-number --no-heading --color=always --smart-case '
  let initial_command = printf(command_fmt.shellescape(a:query))
  let reload_command = printf(command_fmt.('%s'), '{q}')
  let spec = {'options': ['--phony', '--query', a:query, '--bind', 'change:reload:eval '.reload_command]}
  call fzf#vim#grep(initial_command, 1, fzf#vim#with_preview(spec), a:fullscreen)
endfunction

command! -nargs=* -bang RG call RipgrepFzf(<q-args>, <bang>0)

https://user-images.githubusercontent.com/16057481/185954564-b29d8cd7-adc4-4fc8-a310-d6c44f40e116.mp4