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.

MYVIFM and MYVIFMRC variables missed under tmux or gnu screen

+1 vote
asked Sep 2, 2016 in vifm by tagwint

Noticed, that if i use ,c that's shortcut to open my vifmrc file the behavior differs depending on if vifm started from shell of from either tmux or screen

In the first case it works as expected - opens my vifm rc file in editor,
in the latter case however it just open editor with no file.

I have default keymapping

nnoremap ,c :write | execute ':!vim $MYVIFMRC' | restart<cr>

and it's obvious thtat MYVIFM variable is undefined/empty.

I have a vague feeling it's somehow relates to the manner tmux runs/executes (sub)shell
But no enlightenment so far.

1 Answer

+1 vote
answered Sep 3, 2016 by xaizek
selected Sep 3, 2016 by tagwint
 
Best answer

Newer command that doesn't have the issue

Current (since 0.8.2) version of the binding is this:

nnoremap ,c :write | edit $MYVIFMRC | restart<cr>

It also accounts for 'vicmd' option, so is a better choice.

What's wrong with the old one

Another way of getting it fixed is to use %n macro to suppress using terminal multiplexer like this:

nnoremap ,c :write | execute ':!vim $MYVIFMRC %n' | restart<cr>

The reason it's needed is that environment variables are passed from process parents to their children and in the case of terminal multiplexers they are the parents. There are ways to change their environment too, but since it can potentially affect too many unrelated processes, only selected variables are propagated this way.

When :edit is used, vifm does the expansion locally and shell gets expanded path, but with :execute !... command is passed to terminal multiplexer without expansion of environment variables and it's done on their side where there is no $MYVIFMRC as you've discovered.

commented Sep 3, 2016 by tagwint

Explained nice way, thanks a lot!

If you would like to make a bug report or feature request consider using GitHub, SourceForge or e-mail. Posting such things here won't be considered as spam, but this is not a perfect place for it.
...