junegunn / fzf.vim

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

set the file name as the sticky header at the top of preview #1433

Closed ccshao closed 1 year ago

ccshao commented 1 year ago

I use the following snippets to search a particular folder.

  command! -bang -nargs=* ORg
    \ call fzf#vim#grep(
    \   'rg --column --line-number --with-filename --no-heading --color=always --smart-case '
    \   .shellescape(<q-args>), 1, fzf#vim#with_preview({'dir': 'vaults',
    \                                                   'options': ['--preview-window', '+{2}-5']},
    \                                                   'right:50%', 'ctrl-/'), <bang>0)

It works quite nicely, however, when there are lots of match and file paths are long, I get lost on which files the match is found. How to set a sticky header at the top of preview window? Many thanks!

junegunn commented 1 year ago

Given that you installed bat, you can set $BAT_STYLE to display the name of the file and add something like ~3 to --preview-window option like so.

let $BAT_STYLE = 'header-filename,numbers,grid'

command! -bang -nargs=* ORg
  \ call fzf#vim#grep(
  \   'rg --column --line-number --with-filename --no-heading --color=always --smart-case '
  \   .shellescape(<q-args>), 1, fzf#vim#with_preview({'options': ['--preview-window', '+{2}-5,~3']},
  \                                                   'right:50%', 'ctrl-/'), <bang>0)
image
ccshao commented 1 year ago

Thanks very much for the quick solution!