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.

Conditionals in vifmrc again

0 votes
asked Sep 5, 2016 in vifm by tagwint

Hello again,

I am stuck with this:
Default mapping to s calls :shell command and that's fine.

nnoremap s :shell<cr>

I'd like to make it a bit smarter so that if running from under tmux, it starts shell in a new pane below. The approach looks reasonable:

    nnoremap s :if  $TMUX  != ''  
\| !tmux splitw -v -p20<cr>
\|:else
\| :shell<cr>
\|:endif

and indeed it creates a new pane with shell when I am under tmux.
However otherwise it shows no shell anymore. It shows nothing at all.
What could be a reason and how to make it work usual, non-tmux way when there's no tmux behind? I guess i am somehow wrong with syntax, but no clue.

1 Answer

+1 vote
answered Sep 6, 2016 by tagwint

I've managed to get it work by refactoring of tmux pane creation into separate command:

command! tpane :!tmux splitw -v -p20

and then using that command in conditional block:

nnoremap s :if  $TMUX  != ''
                \| :tpane
                \|:else
                \| :shell
                \|:endif<cr>
commented Sep 6, 2016 by xaizek

That's one way of doing this, another one is to use :execute command. There are more commands like :! (which don't end at |) where this is needed and they are listed here along with :execute workaround.

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.
...