The Ultimate Tmux Cheat Sheet & Guide
Prefix default:
Ctrl + b
(can be changed via set-option -g prefix C-a
). All commands assume prefix is Ctrl + b
. Replace as needed if you remap.Getting Started & Sessions
tmux
Start new sessiontmux new -s name
New session with nametmux ls
List all sessionstmux attach -t name
Attach to named sessiontmux detach
Detach (from inside tmux)tmux kill-session -t name
Kill session by nametmux kill-server
Kill all sessions (server)tmux rename-session -t old new
Rename sessiontmux switch -t name
Switch to session
prefix
d Detach from sessionprefix
s Session chooserprefix
$ Rename current sessionprefix
: Open command promptprefix
? List key bindingsprefix
, Rename current windowprefix
w Window chooser
Windows & Tabs
prefix
c Create new windowprefix
p Previous windowprefix
n Next windowprefix
<0-9> Select window by numberprefix
& Kill current windowprefix
. Move windowprefix
f Find window by nameprefix
l Last window
rename-window newname
swap-window -t 2
Swap with window 2move-window -t 3
Move to window 3link-window -s src -t dst
unlink-window
kill-window
display-message '#W'
Show window name
Panes
prefix
% Split verticallyprefix
" Split horizontallyprefix
o Go to next paneprefix
q Show pane numbersprefix
; Toggle between last two panesprefix
x Kill current paneprefix
{ } Swap pane left/rightprefix
z Toggle zoom pane
prefix
<arrow> Move pane focusprefix
Alt + <arrow> Resize panejoin-pane -s 2.1 -t 1.0
Join window 2.1 to 1.0break-pane
Convert pane to windowswap-pane -[UDLR]
Swap pane directionselect-pane -t :.+
Select nextset-window-option synchronize-panes on
Sync panesdisplay-message '#P'
Show pane index
Copy & Scroll Mode
prefix
[ Enter copy modeq
Quit copy modeSpace
Start selectionEnter
Copy selectionPgUp/PgDn
Scroll up/down/
Search forward?
Search backwardn/N
Next/Prev search result
:show-buffer
Show top buffer:list-buffers
List all buffers:save-buffer filename
Save buffer to file:delete-buffer -b N
Delete buffer Nset -g mode-keys vi
Use Vim keys in copy mode
Resizing & Layout
prefix
Alt + ↑/↓/←/→ Resize paneprefix
Space Change pane layoutprefix
q Show pane numbersprefix
{ } Swap panes left/rightprefix
z Zoom/unzoom pane
select-layout even-horizontal
select-layout even-vertical
select-layout main-horizontal
select-layout main-vertical
select-layout tiled
Mouse Support
set -g mouse on
Enable mouse for resizing, selecting, etcset -g mouse off
Disable mouse supportsetw -g mode-mouse on
Enable mouse in copy mode (tmux <2.1)
- Drag border to resize pane
- Click pane/window to focus
- Scroll mouse wheel to scroll history
Scripting & Automation
tmux new-session -d -s mysession
Detached sessiontmux send-keys -t mysession 'top' Enter
Send command to panetmux new-window -t mysession:1 -n 'htop'
tmux split-window -h -t mysession:1
tmux select-pane -t mysession:1.0
# Script Example tmux new-session -d -s dev tmux new-window -t dev:1 -n code tmux send-keys -t dev:1 'vim .' C-m tmux split-window -h -t dev:1 tmux send-keys -t dev:1.1 'npm start' C-m tmux attach -t dev
Config File (~/.tmux.conf)
# Prefix remap set-option -g prefix C-a unbind C-b bind C-a send-prefix # Mouse support set -g mouse on # Vim keys in copy mode setw -g mode-keys vi # Enable 256 color support set -g default-terminal "screen-256color" # Useful titles set -g set-titles on set -g set-titles-string "#S:#I.#P #W" # Split pane shortcuts bind | split-window -h bind - split-window -v # Reload config bind r source-file ~/.tmux.conf \; display-message "Config reloaded!"
Troubleshooting & Tips
- tmux not responding to keys? Are you in a nested tmux session? Default prefix is
Ctrl+b
. TryCtrl+b
twice. - Copy/paste not working? Use
set -g mouse on
and try Shift+Mouse or enable system clipboard withtmux-yank
plugin. - Terminal colors off? Check
set -g default-terminal "screen-256color"
in both~/.tmux.conf
and your terminal emulator. - Sharing tmux? Run
tmux attach -t session
from multiple terminals (same user).
Plugins & Extensions
- TPM (Tmux Plugin Manager) Easy plugin management
- tmux-sensible Best default settings
- tmux-resurrect Restore tmux sessions
- tmux-continuum Continuous saving
- tmux-yank Clipboard integration
Install TPM:
git clone https://github.com/tmux-plugins/tpm ~/.tmux/plugins/tpm
Then add plugins in ~/.tmux.conf
and use prefix + I to install.