junegunn / fzf.vim

fzf :heart: vim
MIT License
9.55k stars 583 forks source link

Help needed: advanced vim configuration #1443

Open Gbeschbacher opened 1 year ago

Gbeschbacher commented 1 year ago

Too stupid for customized RG Command in vim - help needed please.

Hey guys, i am having trouble adapting an advanced vim command explained in your Readme file already and i cannot get it to run as i'd like to.

The following snippet is from my vimrc and it should introduce 2 shortcuts if rg is available as a bash command:

  1. Cmd-F should open an interactive search window where i can enter a search term followed by an optional path e.g. C-F foo app/ should open the interactive search window, i enter the phrase foo as a search keyword and want to limit the search results on the app directory
  2. K should act the same as Cmd-F with the difference that it has already a search term prefilled (the full word under the cursor)

Everything works as expected except the limitation to the given directory. What am i doing wrong here?

if executable("rg")
  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)

  noremap <C-F> :RG<space><CR>
  nnoremap K :RG <C-R><C-W><CR>
endif

Any help or suggestions are appreciated (even if it's only coding style due to me being new in vim and configuring it)

daern91 commented 1 month ago

Did you figure this one out @Gbeschbacher ?

Gbeschbacher commented 3 weeks ago

Unfortunately not, sorry