Painless navigation between panes in tmux
What
iTerm has the same splitting panes feature as tmux. By default you can jump to the pane on a left by pressing a single keystroke Command+Alt+Left. However in Tmux, you need to press two keystrokes: Ctrl-B followed by Left.
Why
I found that I move between panes very often. Hitting a one keystroke instead of two might speed up my workflow.
How
It turns out you can use tmux bind
command with the -n
flag to create a mapping that doesn't require pressing an extra Ctrl-B keystroke.
Steps
- If you use iTerm2, make sure that "option key acts as +Esc" setting is chosen on the Preferences->Profiles->Keys screen
- Put the following into your ~/.tmux.conf
bind -n 'M-Left' select-pane -L
bind -n 'M-Down' select-pane -D
bind -n 'M-Up' select-pane -U
bind -n 'M-Right' select-pane -R
- Reload your tmux session and voala!
Now you can use Alt-Left in tmux to move between panes without pressing Ctrl-B
Also, if you're using vim's navigation keys, you might use h, j ,k , l keys in your tmux mappings to be consistent.
bind -n M-h select-pane -L
bind -n M-j select-pane -D
bind -n M-k select-pane -U
bind -n M-l select-pane -R
More configuration fun
https://github.com/fsproru/dotfiles/blob/master/symlink/tmux.conf
https://github.com/fsproru/dotfiles
Enjoy