Closed jdsutherland closed 6 years ago
Hi @jdsutherland. It is certainly possible to write a mapping to handle this, although it needs to be a bit smart about whether it is talking to tmux or vim. Lucking, we can borrow from vim-tmux-navigator to make it work.
Assuming you wanted to use C-\
as your key sequence to toggle the focus, you could add the following to your ~/.tmux.conf
:
is_vim="ps -o state= -o comm= -t '#{pane_tty}' \
| grep -iqE '^[^TXZ ]+ +(\\S+\\/)?g?(view|n?vim?x?)(diff)?$'"
bind-key -n C-\ if-shell "$is_vim" "send-keys :VtrFocusRunner C-m" "select-pane -l"
A couple of fun details in there:
is_vim
shell command which allows tmux to detect vim and dispatch the correct commandif-shell
to check if vim or tmux, then if in vim, we send :VtrFocusRunner
C-m
at the end of the send keys as that is how tmux treats enter.That said, while the above should work for you, I'd caution that using up a top level key binding like this is consuming a precious resource, and I'd consider not doing that.
Just for clarity, for me, the sequence goes as follows:
<leader>t
<leader>fr
(mapped to :VtrFocusRunner
)C-\
hotkey from vim-tmux-navigator to unzoom and return to vim pane.I'm going to close this now as I think the above should be enough info to get you going, but please feel free to reach out or reopen if needed.
My current TDD workflow (using vim-test with vim-tmux-runner integration) is the following:
VtrFocusRunner
(vim map)last-pane
(via tmux bind)It'd be nice to unify the focus/unfocus to a single mapping.
Would it be possible to make
VtrFocusRunner
a toggle so that it doesn't require separate mappings to zoom/unzoom the runner?Maybe a better solution would be to a write a function that does all 3 (I really should learn vimscript).
Thoughts?