christoomey / vim-tmux-runner

Vim and tmux, sittin' in a tree...
MIT License
291 stars 37 forks source link

Feature request: toggle VtrFocusRunner #76

Closed jdsutherland closed 6 years ago

jdsutherland commented 6 years ago

My current TDD workflow (using vim-test with vim-tmux-runner integration) is the following:

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?

christoomey commented 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:

  1. I've included the magic is_vim shell command which allows tmux to detect vim and dispatch the correct command
  2. We use if-shell to check if vim or tmux, then if in vim, we send :VtrFocusRunner
  3. We need to include 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:

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.