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

Skim != FZF with fzf#vim#grep custom command for path specific fuzzy search #18

Open
casonadams opened this issue May 5, 2021 · 3 comments

Comments

@casonadams
Copy link

The following command does a rg find in my $NOTES dir and works as expected using fzf. The exact same command using skim doesn't seem to respect the rg commands.

"------------------------------------------------
" Note search START
command! -bang -nargs=* Notes
\ call fzf#vim#grep(
\   "rg
\     --column
\     --line-number
\     --no-heading
\     --color=always
\     --smart-case
\     --passthru
\     ''
\     $NOTES
\   ".shellescape(<q-args>),
\   1,
\   fzf#vim#with_preview(),
\   <bang>0
\ )
"------------------------------------------------
@ranelpadon
Copy link

ranelpadon commented Oct 14, 2021

@lotabout I have similar issue. And I have lots of customization for rg and rg + fzf.vim, but it doesn't work with skim.vim. For example, I want to search specific file types only like Python files only (rg --type py) or JS files only (rg --type js). This is useful/practical since it speeds up the search process especially for huge codebase and eliminates noise (that is, excludes file types you don't care about). So, basically I just want to pass some custom args to the rg command (e.g. --type). Similarly, the OP is passing some custom args also.

This is surprisingly easy to replicate though. This sample code in the README doesn't work, at least on my end:

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, shellescape(a:query))
  let reload_command = printf(command_fmt, '{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)

So, when you type :RG, there will be a floating terminal for a very brief moment, then it will vanish. I'm guessing that the plugin couldn't process the command, and just exits.

And ultimately, I just want to add something to base rg command above, like:
let command_fmt = 'rg --type js ...

function! RipgrepFzf(query, fullscreen)
  let command_fmt = 'rg --type py ...'
  ...
endfunction

Also, it seems not possible to pass additional args to this core skim function?

command! -bang -nargs=* Rg call fzf#vim#rg_interactive(<q-args>, fzf#vim#with_preview('right:50%:hidden', 'alt-h'))

Are we missing something?

BTW, thanks for this interesting/promising plugin. :)

@ranelpadon
Copy link

From the source code, fzf#vim#rg_interactive has hardcoded command indeed:

function! fzf#vim#rg_interactive(dir, ...)
  let dir = empty(a:dir) ? '.' : a:dir
  let command = 'rg --column --line-number --color=always '.get(g:, 'rg_opts', '').' "{}" ' . dir
  return call('fzf#vim#grep_interactive', extend([command, 1], a:000))
endfunction

So, couldn't pass additional rg arg dynamically.

@ranelpadon
Copy link

So, a workaround to pass additional rg arg is to define a similar function:

" Grep the Python files only, exclude the unit tests folder/files.
function! RgPy(dir, ...)
  let dir = empty(a:dir) ? '.' : a:dir
  let command = 'rg --type py --glob "!**/tests/**" --column --line-number --color=always '.get(g:, 'rg_opts', '').' "{}" ' . dir
  return call('fzf#vim#grep_interactive', extend([command, 1], a:000))
endfunction

command! -nargs=* -bang RgPy call RgPy(<q-args>, fzf#vim#with_preview('right:60%'))

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

2 participants