Welcome to Vifm Q&A, where you can ask questions about using Vifm. Registration is optional, anonymous posts are moderated. E-mail and GitHub logins are enabled.
0 votes
in vifm by

I want to change arguments passed to fileviewer executable by mapping.
With code like below it doesn't work:

command FilesInTree :
    \| if executable('eza')
    \|    execute 'fileviewer' '*/' 'eza -Tl' . $VIFM_SHOW_FILES_IN_TREE . ' --color-scale=all --no-time --no-permissions --no-user --total-size --color=always --icons=always --follow-symlinks %c'
    \| elseif executable('tree')
    \|    execute 'fileviewer' '*/' 'tree -hC --du %c'
    \| endif
let $VIFM_SHOW_FILES_IN_TREE = 'D'

command SwitchFilesInTree :
    \| if $VIFM_SHOW_FILES_IN_TREE == ''
    \|     let $VIFM_SHOW_FILES_IN_TREE = 'D'
    \| else
    \|     let $VIFM_SHOW_FILES_IN_TREE = ''
    \| endif
    \| FilesInTree

After executing :SwitchFilesInTree happens nothing.
What am I doing wrong here?

1 Answer

0 votes
by

Each time you run :fileviewer command, you add a viewer instead of replacing it. You can make environment variable part of the command that Vifm passes to the shell instead:

if executable('eza')
   execute 'fileviewer' '*/' 'eza -Tl$VIFM_SHOW_FILES_IN_TREE --color-scale=all --no-time --no-permissions --no-user --total-size --color=always --icons=always --follow-symlinks %c'
elseif executable('tree')
   execute 'fileviewer' '*/' 'tree -hC --du %c'
endif

let $VIFM_SHOW_FILES_IN_TREE = 'D'

command SwitchFilesInTree :
    \| if $VIFM_SHOW_FILES_IN_TREE == ''
    \|     let $VIFM_SHOW_FILES_IN_TREE = 'D'
    \| else
    \|     let $VIFM_SHOW_FILES_IN_TREE = ''
    \| endif
    \| FilesInTree

Also note in your original snippet %c needed to be %%c to avoid expanding them when you run :FilesInTree instead of when a viewer is executed.

...