tips
125 tips Tmux
One command, setting or habit at a time about Tmux: what it does, the line to copy and a caveat or two.
Panes 33
-
Lets programs inside tmux send terminal-specific escape codes, such as iTerm2's, past tmux.
set -g allow-passthrough on -
Draws thicker pane borders and points arrows at the active pane.
set -g pane-border-lines heavy -
Sends a command's output from a script into a fresh pane.
make 2>&1 | tmux split-window -I -
Controls the size of the big pane in the main layouts.
set -g main-pane-width 60% -
Clears all other panes in the window in one command.
tmux kill-pane -a -
Protects a pane, such as a running job, from stray keystrokes.
tmux select-pane -d -t 2 -
Evens out pane sizes while keeping your own arrangement.
Ctrl-b E -
Adds a log strip under all your panes instead of under just one.
tmux split-window -f -v -l 10 -
Gives one new pane an extra environment variable without touching others.
tmux split-window -e AWS_PROFILE=staging -
Greys out inactive panes so the active one stands out.
set -g window-style 'fg=colour247,bg=colour236' -
Marks one pane as the source for swap-pane and join-pane.
Ctrl-b m -
Lets you read the error when a pane's command fails.
set -g remain-on-exit failed -
Sets a pane to a precise number of columns or a percentage.
tmux resize-pane -x 80 -
Prints one line per pane on the whole tmux server, in a format you choose.
tmux list-panes -a -F '#{session_name}:#{window_index}.#{pane_index} #{pane_current_command} #{pane_current_path}' -
Moves every pane in a tmux window to the next position while keeping the layout.
tmux rotate-window -D -
Shows a label with a title or the running command in the border of every tmux pane.
set -g pane-border-status top -
Restarts a pane's program in place, with the same layout and starting command.
tmux respawn-pane -k -
Saves all output of a tmux pane to a log file, switched on and off with one key.
tmux pipe-pane -o 'cat >>~/output.#I-#P' -
Opens a temporary floating window in tmux for a quick command, without touching your layout.
tmux display-popup -E -w 80% -h 80% htop -
Pulls a pane out of another window and places it next to the pane you are in.
tmux join-pane -s 2 # take window 2 and put it into this window -
Applies a fixed pane layout straight away, with the number of the layout as the key.
Ctrl-b Alt-1 # even-horizontal -
Rearranges the panes of the current window into the next of tmux's five built-in layouts.
Ctrl-b Space -
Closes only the current pane, asking first, and leaves the rest of the window alone.
Ctrl-b x -
Toggles between the current pane and the one you were in just before.
Ctrl-b ; -
Resizes the active tmux pane in steps of five cells with the Alt and arrow keys.
Ctrl-b Ctrl-Left # 1 cell -
Rearranges all panes in a tmux window into an even grid or evenly sized rows.
select-layout tiled -
Sends a command to a chosen tmux pane from the shell, as if you had typed it there.
tmux send-keys -t work:1.0 'docker compose logs -f' Enter -
Sends everything you type to all panes in the tmux window, handy for the same command on several servers.
setw synchronize-panes on -
Makes tmux splits and new windows start in the current pane's directory instead of your home folder.
bind | split-window -h -c "#{pane_current_path}" -
Shows a big number on every tmux pane for a moment, and pressing a digit selects that pane.
Ctrl-b q -
Moves the active tmux pane one place up or down in the layout without closing anything.
Ctrl-b { # swap with the previous pane -
Moves the active tmux pane out of the split layout into a new window.
Ctrl-b ! -
Makes the active tmux pane fill the whole window, and a second press restores the layout.
Ctrl-b z
Config and keys 27
-
Gives you a visible sign that tmux is waiting for a key.
set -g status-right '#{?client_prefix,#[reverse] PREFIX #[noreverse],} %H:%M' -
Lets you keep the tmux config with your other dotfiles.
mkdir -p ~/.config/tmux -
Creates and switches to a named session from inside tmux.
bind S command-prompt -p 'new session:' 'new-session -A -s "%%"' -
Reopens status bar messages that disappeared too fast.
Ctrl-b ~ -
Lets you browse and change tmux options without the man page.
Ctrl-b C -
Moves between panes with Alt and an arrow key.
bind -n M-Left select-pane -L -
Finds typos in a tmux config before you load it.
tmux source-file -n ~/.tmux.conf -
Checks what an option is really set to on the running server.
tmux show -gv history-limit -
Creates your own shortcuts for long tmux commands at the prompt.
set -s command-alias[100] 'rl=source-file ~/.tmux.conf' -
Sets how long tmux status line messages stay on screen, in milliseconds.
set -g display-time 3000 -
Passes terminal focus in and out events through tmux to programs running inside it.
set -g focus-events on -
Makes the terminal tab or window title show the tmux session and window name.
set -g set-titles on -
Runs a tmux command only if a shell test succeeds, so one config works on many machines.
if-shell 'test "$(uname)" = Darwin' 'set -g status-style bg=blue' 'set -g status-style bg=green' -
Sets how often tmux redraws its status line and refreshes the commands in it.
set -g status-interval 5 -
Runs a tmux command automatically whenever an event such as a pane split happens.
set-hook -g after-split-window "select-layout even-vertical" -
Shows a large clock in a tmux pane, in 12 or 24 hour format, with or without seconds.
tmux clock-mode -
Opens a searchable list of all key bindings, including the ones you added yourself.
Ctrl-b ? -
Lets you press a key several times after one prefix, which suits resizing and moving.
bind -r L resize-pane -R 5 -
Replaces the default split keys with a pipe for side by side and a dash for stacked.
bind | split-window -h -
Cuts the delay tmux adds after Escape, so Vim and similar editors react at once.
set -s escape-time 10 -
Changes the tmux prefix key from Ctrl-b to Ctrl-a, which is easier to reach.
set -g prefix C-a -
Lets you run any tmux command from inside tmux, without leaving the session.
Ctrl-b : -
Tells programs inside tmux the right terminal type, so colours and keys work as expected.
set -g default-terminal "tmux-256color" -
Searches all tmux key bindings from the shell, including the ones you added yourself.
tmux list-keys -T prefix | grep split-window -
Puts the tmux status bar at the top of the screen instead of the bottom.
set -g status-position top -
Adds a key that re-reads ~/.tmux.conf inside a running tmux session.
bind r source-file ~/.tmux.conf \; display-message "Reloaded" -
Turns on mouse support in tmux, so clicking selects panes and the wheel scrolls the history.
set -g mouse on
Sessions 25
-
Starts a background tmux session wider than 80 columns, so scripts don't get wrapped output.
tmux new -d -s report -x 200 -y 50 'top' -
Pauses a command until something in another pane says it's done, without polling or sleep.
tmux wait-for build-done -
Stops the tmux server and everything running inside it.
tmux kill-server -
Cleans up throwaway sessions as soon as you leave them.
tmux new -s scratch \; set destroy-unattached on -
Lets two screens look at different windows of the same session.
tmux new -t work -s work2 -
Recreates the same windows, panes and commands with one command.
tmux has-session -t "$S" 2>/dev/null && exec tmux attach -t "$S" -
Attaches a client that can see a session but not change it.
tmux attach -r -t demo -
Lists every terminal connected to tmux, with session and size.
tmux list-clients -
Kicks a forgotten connection off your session from a list.
Ctrl-b D -
Points a running session at a new project folder.
tmux attach -t main -c ~/projects/site -
Switches a tmux client to another session when its session closes, instead of detaching.
set -g detach-on-destroy off -
Runs an independent tmux server on a named socket, separate from your normal sessions.
tmux -L test -f /tmp/test.conf new -s try -
Prints a tmux session variable as a shell command, so an old pane can pick up the new value.
tmux show-environment -s SSH_AUTH_SOCK -
Exits with success when the named session exists and with failure when it does not.
tmux has-session -t work 2>/dev/null || tmux new -d -s work -
Moves to the previous or next tmux session without detaching first.
Ctrl-b ( # previous session -
Attaches to a session and disconnects every other client that is still attached to it.
tmux attach -d -t work -
Opens a list of all sessions to choose from, with a live preview of each.
Ctrl-b s -
Leaves the tmux session without stopping anything in it, so you can come back later.
Ctrl-b d -
Prints a tmux format such as the session name or pane path to the terminal, for use in scripts.
tmux display-message -p '#S' # session name -
Attaches to the tmux session called work, or creates it when it does not exist.
tmux new -As work -
Starts a command in a detached tmux session, so it keeps running after you log out.
tmux new -d -s backup 'rsync -a /source/ /target/' -
Gives the current tmux session a clearer name without restarting it.
Ctrl-b $ -
Kills all tmux sessions apart from the one you keep, for a quick clean-up.
tmux kill-session -a -t work -
Lists tmux sessions in a format you choose, for example only the name and window count.
tmux ls -F '#{session_name}: #{session_windows} windows' -
Attaches to the tmux session you name, or creates it when it does not exist yet.
tmux new -As work
Windows 23
-
Makes the current window stand out in the status bar.
setw -g window-status-current-style 'bg=yellow,fg=black,bold' -
Moves the current window to a new index or another session.
Ctrl-b . -
Goes straight to the window that rang a bell or printed output.
Ctrl-b Alt-n -
Reaches windows numbered above 9 without cycling through them.
Ctrl-b ' -
Shows the current folder instead of the program in window names.
setw -g automatic-rename-format '#{b:pane_current_path}' -
Starts a command in a new window while you stay where you are.
tmux new-window -d -n sync 'rsync -a ~/photos/ /mnt/backup/photos/' -
Swaps the positions of two tmux windows.
tmux swap-window -s 3 -t 1 -
Creates a new tmux window directly after the current one instead of at the end.
tmux new-window -a -
Finds the tmux window whose name, title or visible text matches a pattern.
tmux find-window 'Permission denied' -
Highlights a tmux window in the status bar after it has printed nothing for a set time.
tmux setw monitor-silence 30 -
Sizes a tmux window to the sessions that have it as current window.
setw -g aggressive-resize on -
Stops tmux from renaming windows after the program running in them.
set-option -wg automatic-rename off -
Switches to a tmux window with the given name if it exists, and creates it if it does not.
tmux new-window -S -n logs 'tail -f /var/log/syslog' -
Puts one running tmux window in a second session, without starting it twice.
tmux link-window -s work:logs -t home: -
Switches to a window by its number, shown in the status bar, with two key presses.
Ctrl-b 0 -
Marks a window in the status bar when something new appears in it while you look elsewhere.
setw -g monitor-activity on -
Moves to the next or the previous window in the session with a single key after the prefix.
Ctrl-b n # next window -
Gives the current tmux window a name you choose, so the status bar tells you what is running where.
Ctrl-b , -
Closes the current tmux window and every pane in it, but asks first.
Ctrl-b & -
Renumbers tmux windows automatically so there is no gap after one is closed.
set -g renumber-windows on -
Toggles between the current and the previous tmux window, like alt-tab for windows.
Ctrl-b l # last window -
Opens a list of all tmux sessions and windows with a preview, so you can jump to any of them.
Ctrl-b w # sessions and windows -
Starts numbering tmux windows at 1, so the first window sits under the 1 key.
set -g base-index 1
Copy mode and scrollback 17
-
Collects text from several places into one paste buffer.
Ctrl-b [ -
Pipes copied text to pbcopy, wl-copy or xclip automatically.
set -g copy-command 'pbcopy' -
Shows where you are in a pane's history while scrolling.
set -g pane-scrollbars modal -
Loads text from a file or a pipe so you can paste it anywhere.
tmux load-buffer ~/snippets/deploy.txt -
Finds the next place a word appears without typing it.
Ctrl-b [ -
Lets tmux copy selected text to the clipboard of your terminal, even over SSH.
set -g set-clipboard on -
Writes the newest tmux copy buffer to a file or to standard output.
tmux save-buffer - | wc -l -
Sets which characters tmux treats as word boundaries when you move by word in copy mode.
set -g word-separators ' ' -
Deletes the scrollback of a tmux pane so copy mode starts fresh.
tmux clear-history -
Enters scrollback straight away and moves one page up, with no mouse and no extra config.
Ctrl-b PageUp -
Selects text in copy mode with the keyboard and copies it into tmux's paste buffer.
Enter # copy and leave copy mode -
Makes copy mode use vi movement and selection keys instead of the emacs style ones.
set -g mode-keys vi -
Shows every paste buffer tmux holds, so you can paste an older copy instead of the newest.
Ctrl-b = -
Prints everything in a tmux pane, scrollback included, so you can grep it.
tmux capture-pane -p -S - | grep -n 'error' -
Saves what a tmux pane shows, including its history, to a text file or the terminal.
tmux capture-pane -p -S -3000 > build.log -
Finds text in a tmux pane's scrollback after Ctrl-b [, with n for the next match.
/error # search forward for 'error' -
Raises how many lines each tmux pane remembers, so long output is still there when you scroll back.
set -g history-limit 50000
Nothing in this filter yet.