Switching tmux panes quickly

Pressing tmux's ctrl+b everytime you want to switch panes is pain.

Here's how you can make switching panes really easy.

Paste these lines into ~/.tmux.conf

bind -n C-h if-shell -bF '#{pane_at_left}'   '' 'select-pane -L'
bind -n C-j if-shell -bF '#{pane_at_bottom}' '' 'select-pane -D'
bind -n C-k if-shell -bF '#{pane_at_top}'    '' 'select-pane -U'
bind -n C-l if-shell -bF '#{pane_at_right}'  '' 'select-pane -R'

then execute this

perl -pi -e 's/\r$//' ~/.tmux.conf

Now you can switch panes like so:

  • ctrl + k: up
  • ctrl + j: down
  • ctrl + h: left
  • ctrl + l: right

My tmux version is 3.2a, if you have a newer version try github.com/christoomey/vim-tmux-navigator

$ tmux -V
tmux 3.2a