brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: bind -n M-Left lets you switch tmux panes without the prefix

Tmux
~/tips/tip-tmux-bind-no-prefix

bind -n M-Left select-pane -L

Moves between panes with Alt and an arrow key.

Ctrl-b and an arrow is two key presses for something you do all day. A root table binding skips the prefix.

bind -n M-Left select-pane -L
bind -n M-Right select-pane -R
bind -n M-Up select-pane -U
bind -n M-Down select-pane -D

-n puts the binding in the root key table, which tmux checks for every key you press, not only after the prefix. So Alt and an arrow now jump straight to the pane in that direction.

The cost is that the program in the pane never sees those keys. That is why I’d pick Alt with arrows, which few shell tools use. Binding a plain letter with -n would make it impossible to type that letter anywhere, which the tmux man page also warns against.

Some editors do use Alt and arrows, for example to move lines. If you want those back in one pane, you can still send the key through with the prefix:

bind M-Left send-keys M-Left

On a Mac, set your terminal’s Option key to act as Meta, otherwise Alt arrows arrive as something else and nothing happens. Check what tmux receives by pressing the key after Ctrl-b /, which on recent versions shows the binding for a key.

Further reading: tmux manual page (OpenBSD)

More Tmux tips tmux new -d -s report -x 200 -y 50 'top' tmux wait-for build-done set -g allow-passthrough on tmux kill-server Ctrl-b [ All Tmux tips (125) All topics

Link