junegunn / fzf.vim

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

preview options delimiter with depth breaks preview window #1430

Open PhantomCloak opened 1 year ago

PhantomCloak commented 1 year ago

Issue

Preview window does not show the line correctly when used with '--delimiter', '/', '--with-nth', '-2..']

What I try to achieve

Wrap or shorten long path names so matches can be more readable

example:

image

What I tried

I used base confing from advanced ripgrep integration then according to this issue https://github.com/junegunn/fzf.vim/issues/741 I add '--delimiter', '/', '--with-nth', '-2..'] to my config that looks like


command! -bang -nargs=* Rg
  \ call fzf#vim#grep(
  \   'rg --column --line-number --no-heading --color=never --smart-case '.shellescape(<q-args>), 1,
  \   fzf#vim#with_preview(), <bang>0)

  function! RipgrepFzf(query, fullscreen)
  let command_fmt = 'rg -g "*.yml" -g "*.cs" -g "*.cpp" -g "*.h" --column --line-number --no-heading --color=always --smart-case %s | sed "s/ \{1,\}/ /g" || 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, '--delimiter', '/', '--with-nth', '-2..']}
  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)
]])

After that issue looks like this instead showing the line that words placed in it only shows beginning of the file

image