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

Thanks again for everything you do for this wonderful file manager!

I created the :togglescreen command, as :screen doesn't provide any output, so it isn't immediately clear if you just enabled or disabled integration with a terminal multiplexer.

" Disable Tmux integration at startup
screen! | screen

" View if Tmux integration is enabled
nnoremap <Space>c :screen?<CR>

" Toggle Tmux integration
nnoremap <Space>C :togglescreen<CR>

command! togglescreen
         \ :if $VIFM_SCREEN == 1
         \ |  echo 'Disabling Tmux integration'
         \ |  let $VIFM_SCREEN = 0
         \ |  screen
         \ |else
         \ |  echo 'Enabling Tmux integration'
         \ |  let $VIFM_SCREEN = 1
         \ |  screen
         \ |endif

Is there a way to read its current status, so there's no need to use variables, something like &screen?

A related question; I am trying to create a mapping that first makes sure Tmux integration is enabled and then opens the selected files in Vim in a split:

noremap <silent> <C-v>v :screen! | :!$EDITOR %f %v<CR>

This works great, but it opens just one file in Vim, even if I selected multiple files. Comparing the results from !echo %f %m and screen! | !echo %f %m confirms that the second command doesn't receive the full file list when two commands are combined.

Things I have tried:
- using :execute
- Doubling the % sign (read here)

1 Answer

+1 vote
by
selected by
 
Best answer

Is there a way to read its current status, so there's no need to use variables, something like &screen?

There is no corresponding option and I think you can just do:

command! togglescreen :screen | screen?

I'm curious why you toggle it? I think it's more typical to just enable it if terminal multiplexer is in use.

I am trying to create a mapping that first makes sure Tmux integration is enabled and then opens the selected files in Vim in a split:

Most :commands reset selection. There is :keepsel prefix-command to prevent it from happening:

noremap <silent> <C-v>v :execute 'keepsel screen!' | !$EDITOR %f %v<CR>

:execute is necessary because otherwise :keepsel will consume the whole line, another alternative:

noremap <silent> <C-v>v :keepsel screen!<CR>:!$EDITOR %f %v<CR>
by

command! togglescreen :screen | screen?

Thanks, that works indeed and is a lot shorter.
Using variables has the benefit that it can be used in the statusline though, as a reminder if multiplexer is enabled or disabled, so I will probably keep using that: set statusline+=" %{$VIFM_SCREEN}"

I'm curious why you toggle it? I think it's more typical to just enable it if terminal multiplexer is in use.

Since I started using Vifm, I've always had it disabled, so I'm used to it. I recently enabled it, and I can definitely see the benefits of opening a new Tmux window when, for instance, opening a text file. However, I think there are also situations where I would prefer Vim to 'replace' Vifm in the same Tmux window when opening a file (the behavior when :screen is disabled). I am toggling at the moment, so I can choose on the fly which behavior I prefer.

Most :commands reset selection. There is :keepsel prefix-command to prevent it from happening:

Thanks a lot for these suggestions. I didn't know about :keepsel. Both commands work beautifully.

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