Add and remove key bindings
A key selected window 10 and was unbound; | and - split; M-n switches windows with no prefix.
Four commands run the whole key system:
bind key command- add a binding you press after
C-b bind -n key command- add one that needs no prefix at all
unbind key- remove a binding
list-keys -T prefix key- show what a key currently does
Bindings live in key tables, and the table decides when a key applies:
prefix- keys pressed after
C-b; wherebindwrites by default root- keys with no prefix;
-nis short for-T root copy-mode/copy-mode-vi- only inside copy mode
bind replaces whatever the key did before, silently. And a careless -n binding fires on every keystroke, so leave it off unless you mean it.
Press C-b :, type bind M-0 selectw -t:=10, Enter, then press C-b M-0.
Window 10, far, is current.
Run open ~/.tmux.conf, add these lines, and save with Ctrl-S:
bind | split-window -h
bind - split-window -v
bind -n M-n next-windowPress C-b :, type source ~/.tmux.conf, Enter.
C-b | now splits left and right; plain M-n changes window with no prefix.
Press C-b :, type unbind M-0, Enter.
list-keys -T prefix M-0 now reports an unknown key.
Exact window targets
In -t :=10, the : says the target is a window and the = demands an exact match on index 10 — without it, 10 would also match a window whose name merely starts that way.
In the configuration file | needs no quoting; only the shell treats it specially.
Here is what just happened.
Each bind wrote into the prefix table, so the keys needed C-b first; -n wrote M-n into root, so it needs nothing. unbind deleted the window-10 binding outright, where another bind would only have replaced it.
- Bind a key to a command; bind replaces an existing binding silently:bind M-0 selectw -t:=10
- Bind a key that works without the prefix:bind -n M-n next-window
- Remove a binding completely:unbind M-0
Go further
list-keyswith no table lists everything;-Nshows the help textC-b ?uses.bind t clock-modeis its own default; binding over it shows how silently a bind replaces.list-keys -T rootafter any new-nbinding is the way to catch one that fires on every keystroke.
- 1
-nmeans no prefix. Leave it off|and-, or they fire on every keystroke. - 2
bind M-0 selectw -t:=10at the prompt, then pressC-b M-0to use it. - 3Put the three
bindlines in~/.tmux.confwithopen ~/.tmux.conf, then:source ~/.tmux.conf. Finish with:unbind M-0.
This is a live terminal. Typing goes to the machine, including Tab. Press Shift and Tab together to move focus back out to the page.
A real terminal, in this tab
Alpine Linux and tmux 3.4 on an x86 emulator. Nothing to install, and no server behind it.
about 15 MB, once
Done when
not started- Some key in the prefix table selects window 10— not done yet
- Window 10 is now the current window of session learn— not done yet
- The | key in the prefix table splits the window left/right— not done yet
- The - key in the prefix table splits the window top/bottom— not done yet
- M-n in the root table runs next-window— not done yet
- M-0 no longer has a binding in the prefix table— not done yet