Skip to content

Wrap $FZF_PREVIEW_PREVIEW_BAT_THEME in quotes. fzf_preview_lines_command not working and shows no error #321

@juanMarinero

Description

@juanMarinero

yuki-yano/fzf-preview.vim 2.16.6
VIM - Vi IMproved 9.1. Included patches: 1-818
bat 0.24.0
Ubuntu 24.04.2 LTS

Optional Configuration Tips README-section shows:
$FZF_PREVIEW_PREVIEW_BAT_THEME = 'OneHalfDark'

In Vim 9.1 I need to prepend let. I did set to a bat theme with spaces:
let $FZF_PREVIEW_PREVIEW_BAT_THEME = 'Solarized (dark)'

Thus, :echo g:fzf_preview_lines_command prints to me:
bat --theme=Solarized (dark) --color=always --plain --number

If I run in Vim (or terminal) any of these 2 cmds they work

:execute "!bat --theme='default' --color=always --plain --number  " . shellescape(expand('%'))
:execute "!bat --theme='Solarized (dark)' --color=always --plain --number  " . shellescape(expand('%'))

If I do NOT wrap the bat-theme in quotes then I get next ERROR on terminal zsh: number expected
bat --theme=Solarized (dark) --color=always --plain --number
On the other hand, next Vim cmd does return NOTHING, nor even in :messages
:call fzf_preview#rpc#command('FzfPreviewLines',)

Please:

  • Prepend let in Optional Configuration Tips. From $FZF_PREVIEW_PREVIEW_BAT_THEME = 'OneHalfDark' to let $FZF_PREVIEW_PREVIEW_BAT_THEME = 'OneHalfDark'.
  • Improve debugging. If fzf_preview#rpc#command (or any other function) fails then an error message helps to fix the problem.
  • Wrap $FZF_PREVIEW_PREVIEW_BAT_THEME of s:bat_theme_option in quotes. plugin/fzf_preview.vim#L12. From:
    let s:bat_theme_option = '--theme=' . $FZF_PREVIEW_PREVIEW_BAT_THEME
    to
    let s:bat_theme_option = '--theme=' . "'" . $FZF_PREVIEW_PREVIEW_BAT_THEME . "'"

Workaround till repo improved. Add next cmds to .vimrc (after loading this plugin). Code explanation: redefine bat_theme_option and all variables that use it; replacing every s: to g: scope.

let $FZF_PREVIEW_PREVIEW_BAT_THEME = 'Solarized (dark)'
let g:bat_theme_option = '--theme=' . "'" . $FZF_PREVIEW_PREVIEW_BAT_THEME . "'"
let g:fzf_preview_lines_command='bat ' . g:bat_theme_option . ' --color=always --plain --number'
let g:fzf_preview_command = 'bat ' . g:bat_theme_option . ' --color=always --plain --number {-1}'

Debug:

:echo g:bat_theme_option 
:echo g:fzf_preview_lines_command
:echo g:fzf_preview_command

Thanks in advance!

PD. Tip to get all bat themes run bat --list-themes. See this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions