It would be useful to get a better understanding of the context of the results that fzf shows when I type in some query, to have fzf show n lines before/after/around the actual matching line.
Agreed! I barely ever use grep since fzf is so amazing. But I like grep's context flags -A NUM, -B NUM, and -C NUM.
This is not exactly what you want, but since 0.18.0, {n} in preview command template evaluates to zero-based line index, so in some cases, you can use it to display the lines around it.
fzf --preview 'tail +$(( {n} + 1 )) /usr/share/dict/words | head -100' < /usr/share/dict/words
Thanks for the suggestion! (and for the absolutely amazing tool!!!) The preview is a little heavy duty for this application, but it certainly is a nice workaround :slightly_smiling_face:
Any way to pipe this?
@junegunn Ibelieve what I want to achieve is related to this so doesn't need an extra ticket
in the vim plugin, and a little script I wrote, the results of rg is displayed in the preview window. ctl down allows one to see the context after but since the preview start is not the file start, it's not possible to scroll up (as much as one wants) in the preview.
Would it be possible to generate a whole file preview and also set which line of the preview should be centered in the preview window? with a option --preview-line for example
@junegunn's workaround is cool! I used it to give context to command line history searches. I also modified the tail math so it gives 5 lines before the match.
alias fzfh='fzf --preview '\''tail +$(( {n} - 4 )) ~/.zsh_history | head -100'\'' < ~/.zsh_history
"Preview offset" option added in 0.23.0.
git grep --line-number '' |
fzf --delimiter : \
--preview 'bat --style=numbers --color=always --highlight-line {2} {1}' \
--preview-window +{2}-/2
https://github.com/junegunn/fzf/blob/master/CHANGELOG.md#0230
Most helpful comment
This is not exactly what you want, but since 0.18.0,
{n}in preview command template evaluates to zero-based line index, so in some cases, you can use it to display the lines around it.