cheat-sheets

tmux

tmux is a terminal multiplexer: persistent sessions, split panes and windows that survive SSH disconnects (OpenSSH Cheat-Sheet).

Default prefix is Ctrl+b. In the tables, “prefix” means press Ctrl+b, release, then the key.

Sessions #

COMMANDDESCRIPTION
tmuxNew session
tmux new -s <NAME>New named session
tmux lsList sessions
tmux attach -t <NAME> / tmux aAttach (most recent with a)
tmux new -A -s <NAME>Attach, or create if missing
tmux kill-session -t <NAME>Kill a session
tmux kill-serverKill everything
prefix dDetach
prefix $Rename session
prefix sSwitch session
prefix ( / )Previous / next session

Windows (tabs) #

KEYSDESCRIPTION
prefix cNew window
prefix ,Rename window
prefix n / pNext / previous window
prefix 0-9Go to window number
prefix wWindow list
prefix &Close window

Panes #

KEYSDESCRIPTION
prefix %Split left/right
prefix "Split top/bottom
prefix arrowMove between panes
prefix oNext pane
prefix zZoom pane toggle
prefix xClose pane
prefix { / }Swap pane
prefix SpaceCycle layouts
prefix Ctrl+arrowResize (hold Ctrl)
prefix qShow pane numbers
prefix !Break pane into its own window

Copy Mode and Scrolling #

KEYSDESCRIPTION
prefix [Enter copy mode (scroll with arrows or PgUp)
qLeave copy mode
/ or ?Search forward / backward (in copy mode)
Space, EnterStart selection, copy (default emacs keys)
prefix ]Paste

Useful ~/.tmux.conf #

tmux
set -g mouse on
set -g history-limit 50000
set -g base-index 1
setw -g pane-base-index 1
set -g renumber-windows on
set -sg escape-time 10
set -g default-terminal "tmux-256color"
setw -g mode-keys vi

bind | split-window -h -c "#{pane_current_path}"
bind - split-window -v -c "#{pane_current_path}"
bind r source-file ~/.tmux.conf \; display "Reloaded"

Reload without restarting: tmux source-file ~/.tmux.conf.

Scripting #

COMMANDDESCRIPTION
tmux send-keys -t <NAME> "<CMD>" EnterType a command into a session
tmux capture-pane -t <NAME> -pPrint the pane contents
tmux new -d -s <NAME> "<CMD>"Run a command in a detached session
tmux split-window -h "<CMD>"Split and run a command

Plugins #

Install TPM: git clone https://github.com/tmux-plugins/tpm ~/.tmux/plugins/tpm, then in .tmux.conf:

tmux
set -g @plugin 'tmux-plugins/tpm'
set -g @plugin 'tmux-plugins/tmux-resurrect'
run '~/.tmux/plugins/tpm/tpm'

Install with prefix I.

Search all sheets

Tip: / or Ctrl/Cmd+K to open, Esc to close.