Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is it possible to add support to move to a tmux pane or tmux window with ctrl + h and ctrl + l ? #423

Open
oca159 opened this issue Dec 19, 2024 · 1 comment

Comments

@oca159
Copy link

oca159 commented Dec 19, 2024

Hi everyone,

I’m curious if it’s possible to add support for navigating to the next or previous tmux window using Ctrl + h or Ctrl + l , when there’s no tmux pane available to the left or right, respectively. I find this behavior much more comfortable and intuitive for seamless navigation.

For reference, this feature is available in another plugin for Zellij: zellij-nav.nvim.

I’d love to know if this functionality is also possible to implement in tmux. Thanks in advance for your help!

@mwpardue
Copy link

I actually just added this to my own copy. I don't know yet how to submit a pull request but below are the changes I made. It's all just additions, nothing removed, so you could either clone my repo or make the changes yourself. This is for the vim side.

https://github.com/mwpardue/vim-tmux-navigator/blob/master/plugin/tmux_navigator.vim#L65-#L71
https://github.com/mwpardue/vim-tmux-navigator/blob/master/plugin/tmux_navigator.vim#L74
https://github.com/mwpardue/vim-tmux-navigator/blob/master/plugin/tmux_navigator.vim#L149-#L151

Then in my .tmux.conf I bound the keys as such:

bind-key -n C-j if-shell "$is_vim" "send-keys C-j" "select-pane -D"
bind-key -n C-k if-shell "$is_vim" "send-keys C-k" "select-pane -U"
bind-key -n C-h if-shell "$is_vim" "send-keys C-h" { if-shell -F '#{pane_at_left}' "previous-window; select-pane -tright" "select-pane -L" }
bind-key -n C-l if-shell "$is_vim" "send-keys C-l" { if-shell -F '#{pane_at_right}' "next-window; select-pane -tleft" "select-pane -R" }

That changes panes like normal, but if you're at the left or right of the window it will move to the previous or next window, respectively. It doesn't wrap top to bottom from a vim pane, but that would be trivial to add.

Note that you have to define let g:tmux_navigator_no_wrap = 0 and let g:tmux_navigator_window_switch = 1. If you try to enable both it will disable the window switch in favor of wrapping.

I hope that helps, and I'm going to try to do a pull request, maybe get it added as an official option.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants