tmux Cheatsheet
Copy Mode and Buffers
Use this tmux reference while you build software engineering projects, review code, or refresh the syntax you reach for most.
Copy Mode
Copy mode is how you scroll back and select text without the mouse. Entering it freezes the pane and gives you a cursor.
| Keys | Action |
|---|---|
prefix [ | Enter copy mode |
prefix ] | Paste the most recent buffer |
prefix PageUp | Enter copy mode and scroll up one page |
q or Esc | Leave copy mode |
Set vi keys once and copy mode behaves like a read-only Vim buffer, which is one fewer set of bindings to remember.
setw -g mode-keys vi
Buffers
tmux keeps its own stack of copy buffers, separate from the system clipboard.
| Keys | Action |
|---|---|
prefix ] | Paste the most recent buffer |
prefix = | Choose a buffer from a list and paste it |
prefix - | Delete the most recent buffer |
tmux list-buffers tmux show-buffer # print the newest buffer tmux show-buffer -b 2 # print a specific one tmux save-buffer out.txt # write a buffer to a file tmux load-buffer in.txt # load a file as a buffer tmux set-buffer "some text" # set one directly tmux paste-buffer # paste into the active pane tmux paste-buffer -t work:1.2 tmux delete-buffer -b 0 echo "text" | tmux load-buffer - # pipe stdin into a buffer
System Clipboard
Getting y in copy mode to reach the OS clipboard depends on the platform.
# macOS bind -T copy-mode-vi y send -X copy-pipe-and-cancel 'pbcopy' # Linux with X11 bind -T copy-mode-vi y send -X copy-pipe-and-cancel 'xclip -in -selection clipboard' # Linux with Wayland bind -T copy-mode-vi y send -X copy-pipe-and-cancel 'wl-copy' # Also copy on mouse drag release bind -T copy-mode-vi MouseDragEnd1Pane send -X copy-pipe-and-cancel 'pbcopy'
On tmux 2.6 and newer, set -g set-clipboard on lets tmux use the OSC 52 terminal escape to set the clipboard directly, which works even over SSH if your terminal supports it.
set -g set-clipboard on
That last point is the reason OSC 52 is worth enabling: copying from a remote tmux to your local clipboard otherwise requires forwarding a clipboard tool.
Mouse Support
set -g mouse onWith mouse on: click to select a pane, drag dividers to resize, scroll to enter copy mode and scroll back, click a window name in the status bar to switch, and double-click or triple-click to select a word or line.
# Scroll wheel enters copy mode instead of sending arrow keys to the shell bind -n WheelUpPane if -Ft= '#{mouse_any_flag}' 'send-keys -M' \ 'if -Ft= "#{pane_in_mode}" "send-keys -M" "select-pane -t=; copy-mode -e; send-keys -M"'
Mouse mode changes how terminal-native selection works: to select text with the mouse for your terminal's clipboard rather than tmux's, hold Shift (on most terminals) while dragging.
Scrollback History
set -g history-limit 50000 # lines kept per pane
tmux clear-history # drop this pane's scrollback tmux clear-history -t work:1.0 tmux capture-pane -p # print the visible pane tmux capture-pane -pS - # print the entire history tmux capture-pane -pS -3000 # the last 3000 lines tmux capture-pane -pS - > pane.log # save it to a file tmux pipe-pane -o 'cat >> ~/tmux.log' # log everything from now on tmux pipe-pane # stop logging
capture-pane -pS - is the answer to "the output I need scrolled past and I want it in a file". pipe-pane is the answer to "log this session from here forward".
Searching Output
prefix [ enter copy mode /error search forward ?error search backward n / N next / previous match
tmux capture-pane -pS - | grep -n "ERROR" # search without copy mode tmux find-window "text" # find a window containing text
Sending Keys
You can type into a pane from outside it, which is what makes tmux scriptable.
tmux send-keys 'ls -la' Enter # type and run tmux send-keys -t work:1.0 'npm test' Enter tmux send-keys -t api C-c # send Ctrl-C tmux send-keys -t api 'clear' Enter tmux send-keys -l 'literal text' # do not interpret key names tmux send-keys -t api Up Enter # rerun the last command tmux respawn-pane -k -t api 'npm run dev' # restart a pane's command
| Key name | Sends |
|---|---|
Enter | Return |
C-c | Ctrl-C |
C-d | Ctrl-D |
M-x | Alt-X |
Escape | Escape |
Tab Space BSpace | The obvious keys |
Up Down Left Right | Arrows |
Displaying Output
tmux display-message "hello" # show in the status line tmux display-message -p '#{pane_id}' # print to stdout instead tmux display-panes # show pane numbers tmux display-popup -E 'htop' # a floating popup (tmux 3.2+) tmux display-popup -w 80% -h 80% -E 'lazygit' tmux confirm-before -p "kill? (y/n)" kill-session tmux command-prompt -p "name:" "rename-window '%%'"
display-popup is a recent addition that covers a real need: run a scratch command (a git UI, a calculator, a quick shell) without disturbing your layout.