fzf-lua
fzf-lua copied to clipboard
Question: preview lags
Both grep and fd previews choke on big text files sometimes taking 5 to 15 seconds to unfreeze in the picker preview. While with vanilla fzf it's still choking but much more responsive so I was wondering how does the preview work do you use your own preview with treesitter or do you use the fzf vanilla preview coloring?
What is the best practice to speed previews up for large files bigger than 500kb for example giant .map or .json files, Given that I don't want to fully hide them I still want to be able to find the text in the preview with rg or see the output with fd?
Thanks
my config https://github.com/kapral18/config.nvim/blob/7f87d49990a0a3034da365c550f8a574a7d33f22/lua/plugins/fzf.lua
my fzf config:
# FZF
set FD_OPTIONS "--hidden --follow"
set -gx FZF_DEFAULT_OPTS "--no-mouse --height 80% --reverse --multi --info=inline --preview='bat {} --color always' --preview-window='right:60%:wrap' --bind=ctrl-d:half-page-down,ctrl-u:half-page-up,ctrl-b:page-up,ctrl-f:page-down"
set -gx FZF_DEFAULT_COMMAND "git ls-files --cached --others --exclude-standard 2>/dev/null || fd --type f --type l $FD_OPTIONS"
set -gx FZF_CTRL_T_COMMAND "$FZF_DEFAULT_COMMAND"
set -gx FZF_ALT_C_COMMAND "fd --type d $FD_OPTIONS"
alias fzfi='git ls-files --cached --others --exclude-standard 2>/dev/null || fd --type f --type l $FD_OPTIONS'
P.S. if this question is not appropriate in issues, I'd appreciate if you could open discussions so that these types of questions could be asked there.
While with vanilla fzf it's still choking but much more responsive so I was wondering how does the preview work do you use your own preview with treesitter or do you use the fzf vanilla preview coloring?
You can’t compare the default previewer to vanilla fzf, fzf-lua defaults uses a neovim buffer to load the file and also apply treesitter highlighting (which is what is most impacting performance), if you want to have a similar experience to vanilla fzf, use the bat
previewer instead (or try the max_peformance
or fzf.vim
profiles).
What is the best practice to speed previews up for large files bigger than 500kb for example giant .map or .json files, Given that I don't want to fully hide them I still want to be able to find the text in the preview with rg or see the output with fd?
Take a look at the default previewer options: https://github.com/ibhagwan/fzf-lua/blob/14d34705906e979d94d8033953d40c64d2d96d02/lua/fzf-lua/defaults.lua#L189-L195
My suggestions:
-
Add a syntax limit either by number of lines
syntax_limit_l
or file sizesyntax_limit_b
(bytes) - without syntax the files that meet this criteria will have no syntax coloring, the performance difference is quite big. -
Experiment with what it means to disable treesitter for the preview and perhaps (either fully or for specific extensions), without treesitter you’d still have syntax coloring but just the “basic”, treesitter requires a lot of heavy lifting.
-
Finally if the files are too big for the previewer you can disable preview completely for large files with
limit_b
.
thanks for the cues I will try those out
ok I basically switch off both syntax and treesitter, and I still have the same lags. I was previously using bat before switching to default because of some other issue I can't remember that bat was not supporting. I probably discussed this in another thread I need to find somewhere. But basically when I search with vanilla fzf what I see is that I can freely switch files without any delay even if in preview the render is stuck due to huge size. Is it achievable within fzf-lua?
I can’t control how neovim behaves when you open a large buffer, if you want the same experience as fzf.vim use bat, if you have issues with bat, open an issue and I’ll fix it.
a tiny offtop @ibhagwan how can I enable highlight of current preview line for bat
bat = {
cmd = "bat",
args = "--style=numbers,changes --color never --highlight-line={?}",
},
a tiny offtop @ibhagwan how can I enable highlight of current preview line for bat
bat = { cmd = "bat", args = "--style=numbers,changes --color never --highlight-line={?}", },
Why aren’t you using fzf-lua’s bat previewer?
Either set winopts.preview.default = “bat”
or run :FzfLua files previewer=bat
- it takes care of everything for you highlight lines included, previews for tags, buffers, etc.
Run :FzfLua profiles
and test fzf-native, max-perf and fzf.vim, they all use bat previewer.
You can use a profile as a base for your setup too: https://github.com/ibhagwan/fzf-lua?tab=readme-ov-file#profiles
fzf-native automatically sets previewer to bat (with line highlights)
indeed setting everything bat solved the problem. Thanks