Welcome to Vifm Q&A, where you can ask questions about Vifm usage. Registration is optional, anonymous posts are moderated. GitHub or Google logins are enabled.
0 votes
in vifm by
edited by

I would like to refer the current directory in a command string sent to the term function. For instance:

 :let $FZF_RES = term("fd -t d '' %d | fzf 2> /dev/tty")
 \| if $FZF_RES != ''
 \|     cd $FZF_RES
 \| endif

The command string seems correct by echo it:

:!!echo "fd -t d '' %d | fzf 2> /dev/tty"

Yet, the fd command receives only %d. I wonder what are the correct expand rules to use for such a situation. Thanks!

1 Answer

0 votes
by
selected by
 
Best answer

Your :let code is probably from a mapping and macros aren't expanded in the body of mappings. They are expanded on a per command basis (e.g., for :! and :touch) and in the body of user defined commands.

Right hand side of :let command is an expression, so you can use expand() function, otherwise you would need to use expand() and :execute command.

This should work:

:let $FZF_RES = term("fd -t d '' ".expand('%d')." | fzf 2> /dev/tty")
\| if $FZF_RES != ''
\|     cd $FZF_RES
\| endif

You can test such things with :echo:

:echo expand('%d')
by

Great it now works... also thanks for the :echo tip.

...