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.

How to refer the current directory (%d) in a command string?

0 votes
asked Jan 15 in vifm by randomizedthinking
edited Jan 15 by randomizedthinking

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
answered Jan 15 by xaizek
selected Jan 16 by randomizedthinking
 
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')
commented Jan 16 by randomizedthinking

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

If you would like to make a bug report or feature request consider using GitHub, SourceForge or e-mail. Posting such things here is acceptable, but this is not a perfect place for them.
...