christoomey / vim-tmux-navigator

Seamless navigation between tmux panes and vim splits
MIT License
5.07k stars 319 forks source link

Zoom to the active vim panel #352

Closed klarkc closed 1 year ago

klarkc commented 1 year ago

I'm an avid user of the vim-tmux-navigator plugin and find it immensely helpful in seamlessly navigating between Vim and Tmux. However, I would like to request a new feature that allows zooming in on the active Vim pane.

Use Case:

I frequently use the Tmux zoom feature (C-a z) to enlarge the current Tmux pane for better visibility. However, when I try to zoom while in a Vim pane, it zooms the active Tmux pane only, rather than zooming within the Vim pane itself.

Desired Behavior:

I would like to be able to zoom within the active Vim pane, similar to the Tmux zoom feature.

Potential Approach:

I believe for that we'll need to detect C-a z on tmux, and trigger the vim pane zoom, but AFAIK vim does not have a native zoom feature.

christoomey commented 1 year ago

Hey @klarkc - glad you enjoy the plugin! Unfortunately as you noted, vim doesn't have a proper concept of "zooming", and while you likely could patch something together, the complexity pushes it out of the realm of something I'd want to add to the plugin itself.

That said, I can offer some pointers if you want to pull this together yourself. It looks like there's a plugin that offers rough zoom support, or you could roll your own with something like:

function! s:ZoomPane() abort
  wincmd |
  wincmd _
endfunction
command! ZoomPane call <sid>ZoomPane()

My guess is the plugin I linked does more, but I didn't look too closely.

From there, you need to define a tmux key bind that checks for vim (you could reuse the $is_vim snippet from the readme) and then uses send-keys to trigger that in vim, in addition to zooming the tmux pane.

klarkc commented 1 year ago

Thanks for the pointers @christoomey. I'm trying troydm/zoomwintab.vim, because it integrates with vim-airline/vim-airline. The command to zoom is <C-w>o.

I'm adding this to my .tmux.conf

# better prefix key
set -g prefix C-a
bind C-a send-prefix
# list of plugins
set -g @plugin 'christoomey/vim-tmux-navigator'
# TMUX plugin manager (keep at the bottom of tmux.conf)
run -b '~/.tmux/plugins/tpm/tpm'
# Smart zoom with awareness of Vim panes
bind-key -n 'C-a z' if-shell "$is_vim" 'send-keys C-w o'

But it's not taking any effect, any ideias or suggestion?

klarkc commented 1 year ago
bind-key z if-shell "$is_vim" 'send-keys C-w o; resize-pane -Z' 'resize-pane -Z'

Did the trick, also had to reload tmux config to take effect

tmux source-file .tmux.conf
christoomey commented 1 year ago

👍 glad to hear you've got something working, and thanks for sharing back here. Even if not in the plugin proper, it's nice to have the notes here for anyone in the future with a similar goal in mind.