-
-
Notifications
You must be signed in to change notification settings - Fork 577
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Configurable preview highlighter for Linux #707
Conversation
This is a nice feature. However I have a small comments and concern with its implementation:
Great idea! |
Hi @wookayin! Thanks a lot for your feedback. Glad you appreciate this feature. Actually, my changes could be considered as a factorization of the logic you're talking about 🙂 In fact, if you work on Linux (and probably on MacOs), you could remove the |
Thanks for your interest in the project. I'm not really into the idea of introducing and maintaining more configuration knobs for echo fzf#vim#with_preview({})
" See https://github.com/junegunn/fzf/blob/master/README-VIM.md#fzfwrap
let opts = { 'source': 'ls', 'window': 'tabnew' }
echo fzf#wrap(opts)
echo fzf#vim#with_preview(fzf#wrap(opts)) It's quite trivial to replicate what it does without using it if you know about the options. For most users, " Files with bat previewer
command! -bang -nargs=? -complete=dir Files
\ call fzf#vim#files(<q-args>, {'options': ['--preview', 'bat -p --color always {}']}, <bang>0)
" Rg using custom preview script
command! -bang -nargs=* Rg
\ call fzf#vim#grep(
\ 'rg --column --line-number --no-heading --color=always --smart-case '.shellescape(<q-args>), 1,
\ 'options': ['--preview', '~/bin/my-custom-preview-script {}']
\ <bang>0)
True, we don't need both scripts. And that's what I think we should do. I still prefer to have an external script file instead of having some shell script embedded somewhere in the bowels of a VimScript file. That way it's easier to test and maintain given that most users are not familiar with VimScript. You can use it outside of Vim separately, and easily copy and modify it to your liking. |
+1 for having an external script for previewing. I suggest we should be able to simply configure which highlighter (e.g. bat, coderay, etc.) should be used (as proposed with Using |
With #719 merged, you can now customize the preview command " let $FZF_PREVIEW_COMMAND = 'nl {} || cat {}'
command! -nargs=* Rg
\ call fzf#vim#grep(
\ 'rg --column --line-number --no-heading --color=always --smart-case '.shellescape(<q-args>),
\ 1,
\ fzf#vim#with_preview('right:50%')) |
I would like to pass custom options to highlighters used for previews (for example to select a specific color theme for
highlight
).This PR is to add a new configuration variable
g:fzf_preview_highlighter
that allows to specify which highlighter to use with specific command line options.The implementation works only on Linux (successfully tested) and probably on Mac (can someone test and confirm please?). I don't have Windows, would be glad if someone could adapt changes for it :)
Example:
allows to use
highlight
with therdark
theme.If the
g:fzf_preview_highlighter
variable is not set, the default behavior is similar topreview.rb
: check ifhighlight
,coderay
,rougify
andcat
exist, and use the first one available.There is also a new
g:fzf_preview_line_highlight
variable that allows to specify the ansi color code used to highlight the line in the preview window that corresponds to the selected one in the list. Default value is\x1b[7m
("REVERSE", the same color code used inpreview.rb
).Examples:
To highlight the line with the bright black background color, use:
For terminals supporting 256-colors, you can specify a 8-bit color code:
You can even specify a 24-bit (true color) color code for terminals supporting it like Konsole:
Screenshot: