Most keys start with the prefix, Ctrl-b by default: hold Ctrl and press b, let go, then press the next key. So Ctrl-b c means Ctrl-b, then c. Commands starting with tmux run in your shell, and lines like set -g go in ~/.tmux.conf (or ~/.config/tmux/tmux.conf). You can also type them without the tmux at the prompt you get with Ctrl-b :. The copy mode keys assume vi keys unless they say otherwise. Session and window names are examples, so swap in your own.
Official links: tmux wiki: Getting started, tmux manual page.
Install and start #
-
Install tmuxDebian, Ubuntu
sudo apt install tmuxRed Hat, Fedorasudo dnf install tmuxAlpinesudo apk add tmuxmacOSbrew install tmux -
Show the tmux versionLinux, macOS
tmux -V -
Start tmuxLinux, macOS
tmux -
Start a named sessionLinux, macOS
tmux new -s work -
Attach to a session, or create it if it doesn't existLinux, macOS
tmux new -A -s work -
Start a session in the background running a commandLinux, macOS
tmux new -d -s work 'htop' -
Show the built-in list of keysLinux, macOS
Ctrl-b ? -
Open the tmux command promptLinux, macOS
Ctrl-b :
Sessions #
-
List sessionsLinux, macOS
tmux ls -
Attach to the last sessionLinux, macOS
tmux attach -
Attach to a named sessionLinux, macOS
tmux attach -t work -
Attach and detach everyone else (fixes a squashed screen size)Linux, macOS
tmux attach -d -t work -
Detach, leaving everything runningLinux, macOS
Ctrl-b d -
Pick a session or window from a treeLinux, macOS
Ctrl-b s -
Go to the previous sessionLinux, macOS
Ctrl-b ( -
Go to the next sessionLinux, macOS
Ctrl-b ) -
Go back to the last session you usedLinux, macOS
Ctrl-b L -
Rename the current sessionLinux, macOS
Ctrl-b $ -
Rename a session from the shellLinux, macOS
tmux rename-session -t work lab -
Switch to another session from the shell inside tmuxLinux, macOS
tmux switch -t work -
Kill a sessionLinux, macOS
tmux kill-session -t workWarning: Stops every program running in that session.
-
Kill every session except the current oneLinux, macOS
tmux kill-session -a -
Kill the tmux server and every sessionLinux, macOS
tmux kill-serverWarning: Stops every program running in every tmux session. Check tmux ls first.
Windows #
-
Make a new windowLinux, macOS
Ctrl-b c -
Go to the next windowLinux, macOS
Ctrl-b n -
Go to the previous windowLinux, macOS
Ctrl-b p -
Go to window 0 to 9Linux, macOS
Ctrl-b 0 -
Go back to the last window you usedLinux, macOS
Ctrl-b l -
Pick a window from a listLinux, macOS
Ctrl-b w -
Find a window by its textLinux, macOS
Ctrl-b f -
Rename the current windowLinux, macOS
Ctrl-b , -
Close the current window (asks first)Linux, macOS
Ctrl-b & -
Make a named window from the shellLinux, macOS
tmux new-window -n logs -
Move the current window to number 1Linux, macOS
tmux move-window -t 1 -
Swap the current window with window 1Linux, macOS
tmux swap-window -t 1 -
Renumber windows to close the gapsLinux, macOS
tmux move-window -r
Panes #
-
Split side by side (left and right)Linux, macOS
Ctrl-b % -
Split top and bottomLinux, macOS
Ctrl-b " -
Move to the pane in a directionLinux, macOS
Ctrl-b ← -
Go to the next paneLinux, macOS
Ctrl-b o -
Go back to the last pane you usedLinux, macOS
Ctrl-b ; -
Show pane numbers, then press one to jump to itLinux, macOS
Ctrl-b q -
Zoom a pane to full size, or back againLinux, macOS
Ctrl-b z -
Close the current pane (asks first)Linux, macOS
Ctrl-b x -
Resize a pane a step at a timeLinux, macOS
Ctrl-b Ctrl-← -
Resize a pane five steps at a timeLinux, macOS
Ctrl-b Alt-← -
Swap the pane with the previous oneLinux, macOS
Ctrl-b { -
Swap the pane with the next oneLinux, macOS
Ctrl-b } -
Cycle through the preset layoutsLinux, macOS
Ctrl-b Space -
Lay out the panes in an even gridLinux, macOS
tmux select-layout tiled -
Turn a pane into its own windowLinux, macOS
Ctrl-b ! -
Move window 2 into this window as a paneLinux, macOS
tmux join-pane -s 2 -
Split and keep the same folderLinux, macOS
tmux split-window -h -c "#{pane_current_path}" -
Type in every pane at onceLinux, macOS
tmux setw synchronize-panes onWarning: Every key goes to every pane in the window. Turn it off with tmux setw synchronize-panes off before typing anything you only mean for one host.
-
Restart the program in a dead paneLinux, macOS
tmux respawn-pane -k
Scrolling, copy and paste #
-
Scroll back (enter copy mode)Linux, macOS
Ctrl-b [ -
Leave copy modeLinux, macOS
q -
Use vi keys in copy mode (add to tmux.conf)Linux, macOS
setw -g mode-keys vi -
Start a selection (vi keys)Linux, macOS
Space -
Copy the selection and leave copy mode (vi keys)Linux, macOS
Enter -
Start a selection (default emacs keys)Linux, macOS
Ctrl-Space -
Copy the selection (default emacs keys)Linux, macOS
Alt-w -
Search up in copy mode (vi keys)Linux, macOS
? -
Search down in copy mode (vi keys)Linux, macOS
/ -
Paste the last copied textLinux, macOS
Ctrl-b ] -
Pick something to paste from all copied textLinux, macOS
Ctrl-b = -
Make v and y select and copy like Vim (add to tmux.conf)Linux, macOS
bind -T copy-mode-vi v send -X begin-selection bind -T copy-mode-vi y send -X copy-selection-and-cancel -
Save the scrollback of a pane to a fileLinux, macOS
tmux capture-pane -p -S - > ~/tmux-output.txt -
Log everything in a pane to a fileLinux, macOS
tmux pipe-pane -o 'cat >> ~/tmux-output.txt' -
Clear the scrollback historyLinux, macOS
tmux clear-history
Scripting tmux #
-
Type a command into a session and press EnterLinux, macOS
tmux send-keys -t work 'htop' Enter -
Run a command in a new windowLinux, macOS
tmux new-window -t work -n logs 'htop' -
Check whether a session existsLinux, macOS
tmux has-session -t work 2>/dev/null && echo running -
Show the current session nameLinux, macOS
tmux display -p '#S' -
Show a message on the status lineLinux, macOS
tmux display 'Backup done' -
Build a three-pane layout from a scriptLinux, macOS
tmux new -d -s work tmux split-window -h -t work tmux split-window -v -t work tmux attach -t work -
List every key bindingLinux, macOS
tmux list-keys -
Show every global optionLinux, macOS
tmux show -g
tmux.conf settings #
-
Reload the config without restartingLinux, macOS
tmux source-file ~/.tmux.conf -
Use Ctrl-a as the prefix instead of Ctrl-bLinux, macOS
set -g prefix C-a unbind C-b bind C-a send-prefix -
Turn on the mouse (click panes, drag to resize, scroll)Linux, macOS
set -g mouse on -
Number windows and panes from 1Linux, macOS
set -g base-index 1 setw -g pane-base-index 1 -
Renumber windows when one closesLinux, macOS
set -g renumber-windows on -
Keep more scrollbackLinux, macOS
set -g history-limit 50000 -
Stop the delay after pressing Esc (good for Vim)Linux, macOS
set -sg escape-time 10 -
Use full colourLinux, macOS
set -g default-terminal "tmux-256color" -
Split with | and - in the same folderLinux, macOS
bind | split-window -h -c "#{pane_current_path}" bind - split-window -v -c "#{pane_current_path}" -
Reload the config with Ctrl-b rLinux, macOS
bind r source-file ~/.tmux.conf \; display 'Config reloaded' -
Move between panes with Alt and the arrows, no prefixLinux, macOS
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 -
Show the host name and time on the right of the status lineLinux, macOS
set -g status-right '#H %H:%M' -
Put the status line at the topLinux, macOS
set -g status-position top
Plugins and remote work #
-
Install the tmux plugin manager (TPM)Linux, macOS
git clone https://github.com/tmux-plugins/tpm ~/.tmux/plugins/tpm -
Load TPM (last line of tmux.conf)Linux, macOS
run '~/.tmux/plugins/tpm/tpm' -
Add a plugin to tmux.confLinux, macOS
set -g @plugin 'tmux-plugins/tmux-resurrect' -
Install the plugins listed in tmux.confLinux, macOS
Ctrl-b I -
Save the whole tmux layout (tmux-resurrect)Linux, macOS
Ctrl-b Ctrl-s -
Restore the saved layout (tmux-resurrect)Linux, macOS
Ctrl-b Ctrl-r -
SSH to a server and attach to tmux in one goLinux, macOS
ssh -t server01 tmux new -A -s main -
Send the prefix to tmux inside tmux (nested over SSH)Linux, macOS
Ctrl-b Ctrl-b -
Show the clockLinux, macOS
Ctrl-b t