tmux changed the way I work. My terminal stopped being something that disappears when I close a window. I SSH into a server without worrying about the connection, and every project has its own session with its windows and panes already where I want them. Once that became normal, I started to wonder what else the thing could do, and the answer is a lot more than the beginners guide covers.
- Time
- 52 min
- Steps
- 9
- Updated
- 2 Dec 2026
You will learn
- A config you can grow into
- Keys that follow your hands
- Copy mode with vi keys and the syste…
- A status bar that tells you things
- Asking tmux questions with formats
This is the second guide, and it picks up where the first one stopped. You build a config in blocks that you can add one at a time, so it grows with you, and you set up keys that fit your hands. Copy mode gets vi keys and sends text to your system clipboard. The status bar learns to show the things you want to know, and formats let you ask tmux questions from the shell and from scripts. After that come layouts and synchronize-panes for typing in several panes at once, naming and moving windows, and what the mouse and customize mode can do. Sessions and projects, popups and menus, plugins and working over SSH have their own guide, the third one: tmux in daily use.
A little history explains why tmux behaves the way it does. Nicholas Marriott started it in 2007 as a permissively licensed terminal multiplexer with most of what GNU Screen could do, and the first import into version control is dated 9 July 2007. Detaching, reattaching and listing sessions already worked then, but there was no status bar and no key remapping. In June 2009 tmux was imported into the OpenBSD base system. Today it is developed in the open on GitHub and runs on Linux, macOS and the BSDs. It keeps changing: popups arrived in version 3.2, passthrough of escape sequences in 3.3, and 3.8, released in September 2026, improved floating panes, which are panes that hover above the tiled ones. That is also why this guide names a minimum version where it matters.
I assume you know the basics: sessions, windows, panes, the prefix and a small ~/.tmux.conf. If any of that is new, the first guide is the place to start, and the boxes below link to it and to the two cheat sheets.
What you need, and what changed since the beginners guide
By now you can start and name a session, detach with Ctrl-b d and attach again, open windows with Ctrl-b c, split panes with Ctrl-b % and Ctrl-b ", zoom with Ctrl-b z, and scroll in copy mode with Ctrl-b [. You also have a starter config with a reload key. If not, the tmux guide for beginners covers all of that.
Check your version first, because a few things here depend on it:
tmux -V
Everything in this guide was tested with tmux 3.8, and most of it works from 3.2 onwards. Where a feature needs a newer version I say so. If your distribution ships something older than 3.2, I would get a newer tmux before going on, because customize mode and some of the clipboard options are missing there.
Before you change anything, keep a copy of the config that works:
cp ~/.tmux.conf ~/.tmux.conf.bak
Then edit ~/.tmux.conf in small steps. Add a few lines, press Ctrl-b r (the reload binding from the beginners guide), and check that the result is what you expected before you add the next few. When something breaks, you know which lines did it. tmux names the problem when a line fails, which helps a lot more when you changed three lines than when you changed thirty.

The yellow text at the top is the message from the reload key. It takes the place of the session name and the window tabs for as long as display-time says, and the clock on the right stays where it is. The beginners config only says Reloaded. The keys block later in this guide adds the file name, and that is the version in the screenshot. If you press the keys and no message shows up, the reload never ran, so look at the binding before you look at the lines you just added.
Reloading has a habit that sooner or later surprises everyone. source-file runs the lines in the file again, on top of what the server already has, and it never resets anything. If you delete a bind line from the file and reload, the binding is still there, because nothing told tmux to remove it. The same goes for options you set and then removed. To start clean you have to restart the tmux server:
tmux kill-server
That ends every session and every program running in them, so only do it when nothing important runs. A gentler way to test a config is a separate, throwaway server. The -L flag gives it its own socket, so it shares nothing with the tmux you work in:
# start a test server that reads your config
tmux -L test -f ~/.tmux.conf new -s try
# when you are done, kill only that server
tmux -L test kill-server
It reads the config from scratch each time you start it, the way your real tmux will after a reboot. I would use it whenever you change something big, such as the status bar.
The last tool you need is a way to ask tmux what it really has. tmux show -gv followed by an option name prints the current value and nothing else:
tmux show -gv mouse
tmux show -gv history-limit
Check that it worked: the first line prints on if you kept the mouse line from the beginners guide, the second prints the number you set. If you get invalid option, the name is misspelled or your version does not have that option.
Step 1 of 9: A config you can grow into
The beginners config was a handful of lines. The one in this guide is longer, so I split it into three blocks: basics, keys, and the look of the status bar. Each block can go in on its own, which fits the small-steps habit, and the later sections of this guide refer back to them as the config. The daily-use guide adds blocks of its own for popups, nested tmux and plugins. The basics block comes first, in three pieces.
You will see set -g, set -s and setw mixed together, because tmux options live at different levels. Server options apply to the whole tmux server and are set with set -s. Session options belong to a session, and set -g sets the global value that every session inherits. Window options belong to windows and are set with setw (short for set -w), again with -g for the global value. In practice you rarely have to get this right: the man page says that for a normal option tmux infers the scope from the option name. That is why set -g mode-keys vi works even though mode-keys is a window option. I still write the flags where they belong, because it tells me later what kind of option a line sets.
# basics: colours and terminal
set -g default-terminal "tmux-256color"
set -as terminal-features ",xterm-256color:RGB"
set -sg escape-time 10
set -g focus-events on
default-terminal is the terminal type tmux announces to the programs inside it, through the TERM variable. tmux-256color tells them they can use 256 colours, italics and the rest. In tmux 3.8 this is already the default, so the line is mostly documentation; I keep it so the setting is explicit. It only works if the machine has a terminfo entry with that name. Check it with infocmp tmux-256color: if it prints a long description you are fine, and if it says it cannot find the entry (older macOS systems and some minimal servers), use screen-256color instead.
terminal-features tells tmux what your outer terminal can do. The RGB feature for xterm-256color means: this terminal handles 24-bit colour, so pass hex colours through instead of rounding them to the nearest of 256. That is what makes the colours in the status bar later look the way they are written. -a appends to the list and -s makes it a server option. If your terminal reports a different TERM outside tmux, put that name there instead. A side effect of -a: every reload appends the same entry again, so after a few reloads tmux show -s terminal-features lists xterm-256color:RGB twice or more. It does no harm, and you can see the reload habit from above at work.
escape-time is how long tmux waits after you press Escape to see whether it is the start of a longer key sequence. Older versions waited 500 milliseconds, which makes leaving insert mode in vim feel sticky. 10 is plenty on any normal connection, and 3.8 already uses it. focus-events passes focus changes from your terminal to programs such as vim, so they notice when you switch away and back. The man page says to detach and attach again after changing it.
Check that it worked:
tmux show -gv escape-time
tmux show -gv default-terminal
echo $TERM
The first prints 10. The last two, run inside a new tmux pane, both print tmux-256color.
# basics: behaviour
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
The first four lines come from the beginners guide: mouse support, a long scrollback (the default is 2000 lines), and counting windows and panes from 1 so the numbers match the keyboard row. renumber-windows is new. When you close window 2 out of 1, 2 and 3, tmux renumbers the third one to 2, so there are no gaps and Ctrl-b 2 always means the second window. The targets in the formats section, and the workspace script in the daily-use guide, assume the 1-based numbers, so keep these lines together.
# basics: copy, keys and sizes
set -g set-clipboard on
set -g mode-keys vi
set -g status-keys emacs
setw -g aggressive-resize on
set -g display-time 2000
set -g display-panes-time 2000
set-clipboard on lets tmux put copied text on your terminal’s clipboard with an escape sequence. It gets its own explanation in the copy mode section, because it is the part that confuses people most. mode-keys vi gives copy mode vim-style keys. status-keys emacs keeps the command prompt (Ctrl-b :) on the emacs-style keys your shell probably uses, with Ctrl-a for the start of the line and Ctrl-e for the end. That is the default, and I set it on purpose so that nobody, me included, flips it to vi later and wonders why the prompt behaves oddly.
aggressive-resize matters when the same window is shown in two sessions on screens of different sizes. Without it, tmux sizes the window for every client that has it open and you get dotted filler on the bigger screen. With it on, a window is only shrunk for the clients actually looking at it. The man page notes it is good for full-screen programs and less so for shells. I keep it on anyway, because the dotted filler bothers me more. display-time keeps messages in the status line for two seconds instead of 750 milliseconds, long enough to read them. display-panes-time does the same for the numbers from Ctrl-b q, which by default vanish after one second.
Check that it worked: tmux show -gv mode-keys prints vi, tmux show -gv set-clipboard prints on, and tmux show -gv display-time prints 2000. Close a window in the middle of your list and watch the numbers close up in the status bar.
Each command prints a bare value without the option name in front of it, which is what the -v adds, so the output also works in a script. The first three come from the basics block, and 50000 is the scrollback from the behaviour lines. status-position belongs to the look block in the status bar section, so it only says top once you have added that block. If a value is still the old one after a reload, look for a typo in that line and for an error in the status line right after Ctrl-b r.
Step 2 of 9: Keys that follow your hands
The default keys are fine for a while. After that you notice which ones you press a hundred times a day, and those should be easy. This is the keys block of the config:
# keys
bind r source-file ~/.tmux.conf \; display-message "Reloaded ~/.tmux.conf"
bind | split-window -h -c "#{pane_current_path}"
bind - split-window -v -c "#{pane_current_path}"
bind c new-window -c "#{pane_current_path}"
bind h select-pane -L
bind j select-pane -D
bind k select-pane -U
bind l select-pane -R
bind -r H resize-pane -L 5
bind -r J resize-pane -D 5
bind -r K resize-pane -U 5
bind -r L resize-pane -R 5
bind S setw synchronize-panes \; display-message "synchronize-panes #{?pane_synchronized,on,off}"
The reload and the two split keys are the ones from the beginners guide, with a longer message. bind c replaces the default new-window key with one that opens the new window in the folder of the pane you are in, the same trick the split keys use. #{pane_current_path} is a format, a variable tmux fills in when the key runs. The formats section of this guide goes much deeper into those.
h j k l move between panes like the arrow keys in vim: left, down, up, right. H J K L resize the active pane by five cells. The -r makes these keys repeatable: after Ctrl-b H you can press H again, and again, without the prefix, as long as each press comes within the repeat-time. That is 500 milliseconds by default. Press anything else, or wait, and you are back to normal. Repeat is lovely for resizing and a trap for anything else, because a key you meant for the shell gets eaten by tmux if you type it too soon after a repeatable binding. That is why only the resize keys have it.
Ctrl-b S toggles synchronize-panes, which sends what you type to every pane in the window at once. The beginners guide did this through the command prompt; the layouts section below explains the key and its message.
Two ideas explain how these lines are put together: key tables and command chaining.
Every binding lives in a key table. prefix holds the keys you press after Ctrl-b, and a plain bind goes there. root holds keys that work without the prefix: bind -n F5 ... and bind -T root F5 ... are the same thing. Use that table sparingly, since a root key is taken away from every program running inside tmux. Copy mode has its own tables, copy-mode for the emacs keys and copy-mode-vi for the vi keys, and bind -T copy-mode-vi adds to the second. You can also make your own tables, and the daily-use guide uses one to handle tmux inside tmux. unbind removes a key from a table, for example unbind -T prefix t.
Chaining is how one key runs more than one command. In the config file you separate them with \;, as in the reload line: source-file first, then display-message. The backslash matters. A bare ; ends the bind command, so the second command runs once while the file loads and is not part of the key at all. On the shell command line there is one more layer, because the shell eats the backslash. There you write it as '\;' in quotes:
tmux bind x display-message one '\;' display-message two
The quoting of formats is the other thing to watch. #{pane_current_path} goes inside double quotes in a bind line, so tmux expands it when the key runs and passes the result to split-window as one argument.
The best way to check what a key does is to ask tmux. tmux list-keys prints every binding, -T limits it to one table, and a key name after it limits it to that key. With grep you can pull out a group:
tmux list-keys -T prefix | grep -E 'resize-pane -[LDUR] 5'
Each line is one binding, written as the command that would create it. bind-key -r -T prefix H resize-pane -L 5 is the first line of the block above, with the table spelled out. The -r in every line is the repeat flag. Below the four new keys are the built-in ones with Alt and the arrow keys, the five-cell resize from the beginners guide, which tmux binds with -r too. That output is also the quickest proof that a reload picked up your bind lines.
Some of these keys replace defaults you may already use. Ctrl-b l is last-window by default, the toggle back to the previous window that the beginners cheat sheet lists. After this config, l moves to the pane on the right. Ctrl-b L switches to the last session by default, and here it resizes. h, j, k, H, J and K were free in tmux 3.8. Before you override any key, look at what it does now:
tmux list-keys -T prefix l
tmux list-keys -T prefix L
Check that it worked: before the config loads, the first prints bind-key -T prefix l last-window. After the reload it prints select-pane -R instead.
If you miss last-window, give it another key. Tab would read well, but tmux 3.8 already binds Ctrl-b Tab to something of its own, so check with tmux list-keys -T prefix Tab before you take it. a is free in 3.8:
bind a last-window
Step 3 of 9: Copy mode with vi keys and the system clipboard
Copy mode in the beginners guide was mostly for scrolling. With vi keys and three bindings it turns into a quick way to grab an error message, a path or a line of output without touching the mouse. With mode-keys vi set, these are the keys inside copy mode (Ctrl-b [):
h j k lor the arrow keys move the cursor.wandbjump a word forward and back.0goes to the start of the line,$to the end.Ctrl-uandCtrl-dmove half a page up and down.gjumps to the top of the history,Gto the bottom./searches down,?searches up.nrepeats the search,Nrepeats it in the other direction.vstarts a selection (with the bindings below),Vselects whole lines,Ctrl-vswitches to a rectangle selection.ycopies the selection and leaves copy mode (with the bindings below).qleaves copy mode without copying.
Out of the box, vi mode starts a selection with Space and copies with Enter, and v toggles the rectangle. If you use vim, your fingers expect something else. These three lines from the keys block fix it:
bind -T copy-mode-vi v send -X begin-selection
bind -T copy-mode-vi C-v send -X rectangle-toggle
bind -T copy-mode-vi y send -X copy-pipe-and-cancel "pbcopy"
send -X sends a copy mode command instead of a key. begin-selection starts selecting, rectangle-toggle switches between line and block selection, and copy-pipe-and-cancel copies the selection into a tmux buffer, pipes it into the command you give it, and leaves copy mode. Space and Enter keep working as before.
Say a log scrolled past and you want the line with the error. Press Ctrl-b [, type ?ERROR and Enter to search up, then 0 to go to the start of the line, v to start selecting and $ to extend to the end. Press y and the line is copied.
The blue bar is the selection, here the whole line 21:31 ERROR job 51 failed: timeout. The colour comes from mode-style in the status bar section. The counter [0/46] at the top right is the copy mode position: how far up you are, out of how many lines of history. After y the highlight and the counter disappear and you are back at the prompt.
The rectangle is for output in columns, such as ls -l or df -h. Sometimes you only want the sizes and not the names next to them. A normal selection runs from where you started to where you are now and takes every full line in between. A rectangle takes only the block between the two corners. To try it, print a small table:
for i in $(seq 1 12); do echo "item$i $((i*13)) KB 2026-12-0$((i%9+1))"; done
Press Ctrl-b [, move to the first digit of a size, press v to start the selection and Ctrl-v to turn it into a rectangle. Then move down and to the right until the block covers the column, and press y.
The blue block covers the sizes of item5 to item9. The names on the left and the dates on the right stay out of it, so after y you have five sizes, one per line, ready to paste into a calculator or a spreadsheet. The window tab says 1:[tmux] while copy mode is on, the automatic name that the section about naming windows explains. Ctrl-v again switches back to a normal selection without losing your start point.
Where the copied text ends up depends on your setup. There are three routes, and you can combine them.
The first is the pipe in the y binding. pbcopy is the macOS command that writes to the clipboard, so the text is in your clipboard and Cmd-v pastes it anywhere. On Linux, use wl-copy on Wayland, or xclip -selection clipboard on X11 (install the package first). This only works on your own machine. When tmux runs on a server over SSH, pbcopy on that server has no idea your laptop exists.
The second is set-clipboard on from the basics block. tmux then sends the copied text to your terminal with an escape sequence called OSC 52, and the terminal puts it in the clipboard. Because the sequence travels down the same connection as everything else, this also works when tmux runs on a server and you are connected over SSH, which is the reason I like it. It needs a terminal that supports OSC 52: Ghostty, iTerm2, kitty, WezTerm, Alacritty and recent versions of Windows Terminal do, and Apple’s Terminal does not. Some terminals ask for permission first or have it switched off by default, so look in the settings if nothing arrives. The clipboard page in the tmux wiki has the details per terminal.
The third is copy-command, a server option from tmux 3.2. It sets the command that copy-pipe uses when you give it none:
set -s copy-command "pbcopy"
That matters for the mouse. With mouse on, dragging over text enters copy mode and selects, and when you let go of the button tmux copies the selection and leaves copy mode. That release is bound to copy-pipe-and-cancel without a command, so with copy-command set, a mouse selection also reaches pbcopy. Without it, and without a terminal that handles OSC 52, the mouse selection only ends up in a tmux buffer.
Keep in mind that tmux has its own buffers, separate from the system clipboard. Every copy goes into a tmux buffer first, whatever else happens. Ctrl-b ] pastes the most recent tmux buffer into the active pane, which works even when the clipboard part failed. Ctrl-b = opens a list of all buffers, so you can pick an older one and press Enter to paste it. Cmd-v or Ctrl-Shift-v in your terminal pastes the system clipboard. If those two give different text, the clipboard step failed, and the three routes above tell you where to look.
The newest buffer is at the top and already selected, so Enter straight away pastes the same text as Ctrl-b ]. tmux names the buffers buffer0, buffer1 and so on in the order they were made, and each line shows the time of the copy and the start of the text. The number in brackets is a shortcut: press 2 and the oldest one, alpha, goes into the pane at once. d deletes the selected buffer.
Check that it worked: select something with v and y, then run pbpaste on macOS (or wl-paste on Wayland) in a pane. It prints what you copied.
Step 4 of 9: A status bar that tells you things
The beginners guide ended the status bar with a word of caution: a clock, the session name and the window list are plenty. I still think so. The bar in this guide shows exactly those, plus two labels that appear only when something needs your attention. This is the look block:
# look
set -g status-position top
set -g status-interval 5
set -g status-style "bg=#1e1e2e,fg=#cdd6f4"
set -g status-left-length 30
set -g status-left "#[bold,fg=#1e1e2e,bg=#e8872a] #S #[default] "
set -g status-right-length 60
set -g status-right "#{?client_prefix,#[bg=#f38ba8 fg=#1e1e2e bold] PREFIX #[default] ,}#{?pane_synchronized,#[bg=#f9e2af fg=#1e1e2e bold] SYNC #[default] ,}#[fg=#a6adc8]%H:%M %d %b "
set -g window-status-format " #I:#W "
set -g window-status-style "fg=#a6adc8"
set -g window-status-current-format "#[bold] #I:#W#{?window_zoomed_flag, Z,} "
set -g window-status-current-style "bg=#313244,fg=#cdd6f4"
set -g pane-border-style "fg=#45475a"
set -g pane-active-border-style "fg=#89b4fa"
set -g message-style "bg=#f9e2af,fg=#1e1e2e"
set -g mode-style "bg=#89b4fa,fg=#1e1e2e"
status-position top moves the bar to the top of the screen. That is taste: I find the top easier to glance at, and the bar no longer sits right next to the shell prompt. status-interval 5 redraws the bar every five seconds instead of every fifteen, so the clock and anything else that changes keep up.
The lines ending in -style set colours for a whole area: status-style for the bar, window-status-style for the window tabs, window-status-current-style for the active tab, the two border styles for the lines between panes (blue around the active one), message-style for messages and the command prompt, and mode-style for the selection in copy mode, the blue you saw in the previous section. A style is a list of fg= for the text colour, bg= for the background, and attributes such as bold. Colours can be names like red, colour0 to colour255, or hex values like #1e1e2e. Hex only looks right when tmux knows the terminal does 24-bit colour, which is what the RGB line in the basics block is for. Without it, tmux rounds each hex value to the nearest of 256 colours, and your carefully chosen grey turns into a slightly different grey.
Inside the text of the bar, #[...] switches style midway. In status-left, #[bold,fg=#1e1e2e,bg=#e8872a] starts an orange block with dark bold text, #S puts the session name in it, and #[default] goes back to the bar’s normal style. The -length options set how many characters the left and right parts may take. The defaults are short, and a long session name or a full right side gets cut off without them.
The window tabs use two formats. #I is the window index and #W its name, so window-status-format draws 1:editor with a space on each side. The current window has its own format with bold text and a conditional at the end.
The conditionals are what make this bar useful. #{?condition,yes,no} shows the first text when the condition is true and the second when it is not. Three of them appear here:
#{?window_zoomed_flag, Z,}adds aZto the active tab while a pane is zoomed, and nothing otherwise.#{?client_prefix,...,}shows a pinkPREFIXlabel while tmux is waiting for the key afterCtrl-b.#{?pane_synchronized,...,}shows a yellowSYNClabel while synchronize-panes is on, the toggle fromCtrl-b S.
After the labels, %H:%M %d %b is the time and date, with the same codes as the date command.
Watch the commas, because nearly everyone trips over them once. A conditional uses commas to separate its parts, and a style uses commas to separate its colours. Put a style with commas inside a conditional and tmux splits it in the wrong place. Try it on the command line:
tmux display -p '[#{?#{==:1,1},#[bg=red,fg=black] ON #[default],off}]'
tmux display -p '[#{?#{==:1,1},#[bg=red fg=black] ON #[default],off}]'
The first prints a broken [#[bg=red], cut off at the comma inside the style. The second prints the whole label. The fix is to separate the parts of a style with spaces, which the man page allows just as well as commas. That is why the labels in status-right read #[bg=#f38ba8 fg=#1e1e2e bold], while status-left, which has no conditional around it, can use commas. The other way out is to escape each comma as #,, but spaces are easier to read.
Reload with Ctrl-b r, and the bar jumps to the top. Then press Ctrl-b and look at the right side before you press the next key.
From left to right: the session name work in the orange block, then the tabs. 1:editor Z has the lighter background because it is the active window, and the Z says one of its panes is zoomed. 2:server and 3:logs are the other windows. On the right is the pink PREFIX label, because the screenshot was taken right after Ctrl-b; it goes away as soon as you press the next key. Then come the time, 21:30, and the date, 01 Dec.
Check that it worked: tmux show -gv status-position prints top, and pressing Ctrl-b shows the PREFIX label. Press Ctrl-b S in a window with two panes and SYNC appears next to the clock. Press it again to turn it off.
The colours are a dark palette that goes with most dark terminal themes, and the orange is the one this site uses. Change them freely. If a colour comes out wrong, tmux show -gv status-style prints what tmux actually has, which catches a typo in a hex code faster than staring at the bar.
Two more options change the shape of the bar. status-justify decides where the window list sits: left is the default, and centre puts the tabs in the middle, between the session name and the clock. status switches the bar on or off, and a number from 2 to 5 gives it that many lines. Try them from the shell before you put anything in the file:
tmux set -g status-justify centre
tmux set -g status 2
The tabs now sit in the middle of the top line, with the session name and the clock at the edges. The second line is what tmux draws by default for an extra line: a P: label and the panes of the current window, here just one. It reads 1:[shell]* because the pane got the title shell with tmux select-pane -T 'shell', and the * marks the active pane, the same flag the window list uses. I find one line enough, but a pane list can help on a wide screen with many panes. tmux set -g status on brings you back to a single line.
Step 5 of 9: Asking tmux questions with formats
You have already used a format without calling it one. The -c "#{pane_current_path}" at the end of the split keys in the config is a format, and so is #S in the status bar. A format is a piece of text with #{...} variables in it, and tmux replaces each variable with the current value: the session name, the window number, the folder the pane is in, its size. Once you know how to ask for those values, you can use them in the status bar, in key bindings and in your own shell scripts. The rest of this guide leans on them, so I would spend ten minutes here.
The quickest way to try one is tmux display -p. The -p prints the result to your shell instead of showing it in the status line, so you can read it and pipe it into other commands:
tmux display -p '#{session_name}'
tmux display -p '#{pane_current_path}'
tmux display -p '#S:#I.#P #{pane_current_command} #{pane_width}x#{pane_height}'
The last line uses the short forms. #S is the session name, #I the window index, #P the pane index and #W the window name. They are older shorthands for the long variables and they still work, but only a handful of variables have one, so I would learn the long names and keep the short ones for the status bar where space is tight.
The list- commands take a format too, with -F. They print one line per session, window or pane, and the format decides what goes on that line. In scripts that is the useful part: you get exactly the columns you asked for and nothing to strip off:
# every session, how many windows, and whether someone is attached
tmux list-sessions -F '#{session_name} #{session_windows} #{session_attached}'
# the windows of the current session
tmux list-windows -F '#{window_index} #{window_name} #{window_panes} pane(s) #{?window_active,(active),}'
# every pane on the whole server, with what runs in it and where
tmux list-panes -a -F '#{session_name}:#{window_index}.#{pane_index} #{pane_current_command} #{pane_current_path}'
The -a on list-panes means all panes in all sessions. Without it you only get the panes of the current window. The session:window.pane at the start of each line is the same target notation that -t takes, so you can copy a line of output straight into a send-keys or kill-pane command.
The screenshot shows two of these commands in a session called work:
The first command printed work:1.1 tmux 92x17. That is session work, window 1, pane 1 (the numbers start at 1 because of base-index in the config), and a pane of 92 columns by 17 rows. The middle value is a small surprise: pane_current_command says tmux, because at the moment the format was expanded the program in the foreground of that pane was the tmux display command itself. Ask from another pane, or from a script, and you see bash, vim or whatever really runs there.
The second command printed three lines, one per window: 1 editor 1 pane(s) (active), 2 server 1 pane(s) and 3 logs 1 pane(s). Only the first one says (active), and that comes from the conditional at the end of the format.
That is the same #{?condition,if true,if false} conditional as in the status bar. The condition is usually another variable, and tmux treats it as true when it is not empty and not 0. So #{?window_active,(active),} prints (active) for the active window and nothing for the others, because the part after the second comma is empty.
You can also compare values. #{==:a,b} gives 1 when both sides are equal and 0 when they are not, and #{m:pattern,string} matches a string against a shell-style pattern (pattern first, then the string). Both fit inside a conditional:
tmux display -p '#{==:#{session_name},work}'
tmux display -p '#{m:*vim*,#{pane_current_command}}'
tmux display -p '#{?#{==:#{session_name},work},this is work,somewhere else}'
The last line nests a comparison inside a conditional and prints one sentence or the other. You will not need this every day, but it is how status bars change colour when you are in a particular session, and how a binding can behave differently depending on what runs in the pane.
The first command compares the session name with work and prints the first text, because they match. The second asks whether the session name matches the pattern w* and prints 1; in a session called notes it would print 0. Both use the short #S inside the comparison, which works just as well as #{session_name}. The last one runs a conditional for every pane on the server. This server has a single pane, so you get one line ending in active, and every other pane would say idle.
Formats turn up in three places, and they work the same in each:
- The status bar. Everything in
status-left,status-rightand the window formats is a format, expanded again every few seconds (that is whatstatus-intervalsets). - Key bindings.
bind | split-window -h -c "#{pane_current_path}"opens the new pane in the folder of the pane you split from. Without the format, the new pane starts in the folder where you first started the session. - Scripts.
tmux display -pandlist-* -Fare how a shell script asks tmux where it is, what is open and what to do next.
There are a lot of variables, and I would not try to memorise them. The full list is in man tmux under FORMATS, and the tmux wiki has a page about working with formats that explains the syntax with examples. When you find a name that sounds right, try it with tmux display -p before you put it in your config. An unknown variable simply expands to nothing, so an empty line is your hint that you misspelled it.
The page opens with what formats are and where they are used, then goes through the syntax: variables, conditionals, comparisons and the modifiers that cut or change a value. The list on the right links to the other wiki pages, including Getting Started and the clipboard page. Keep it open in a tab while you build a status bar.
These are the variables I would know by name. All of them exist in tmux 3.8, and tmux display -p prints each one:
session_name: the name of the session, the same as#S.session_windows: how many windows the session has.window_indexandwindow_name: the number and name of the window, as in the status bar.window_panes: how many panes the window has.window_zoomed_flag:1while a pane in the window is zoomed withCtrl-b z.pane_index: the number of the pane, the oneCtrl-b qshows.pane_current_command: the program in the foreground of the pane, such asbashorvim.pane_current_path: the folder the shell in the pane is in right now.pane_widthandpane_height: the size of the pane in columns and rows.pane_synchronized:1when synchronize-panes is on (more about that in the next section).client_prefix:1while you have pressed the prefix and tmux waits for the second key. It belongs to a client, the terminal you are attached from, so it is empty when you ask from a script with nobody attached.host_short: the host name without the domain, handy in a status bar when you work on more than one machine.
Check that it worked: run tmux display -p '#{session_name} #{window_index} #{pane_current_path}' inside tmux. You should get the name of your session, the number of the window you are in and the folder of the pane, on one line. Then cd somewhere else and run it again. The path follows you.
A few catches, most of which give you a puzzling result instead of an error:
- Always quote a format in the shell, and use single quotes. In bash, a word that starts with
#starts a comment, sotmux display -p #{session_name}without quotes runs plaintmux display -pand prints tmux’s default message instead (something like[work] 1:editor, current pane 1). Single quotes also stop the shell from touching a$or!in the format. - Quote it in
~/.tmux.conftoo. The config treats an unquoted#the same way, so a line likeset -g @x #{session_name}stops with an error. That is why every format in the config from this guide sits in quotes. - A format is expanded when the command runs.
bind | split-window -c "#{pane_current_path}"works because tmux expands it each time you press the key, not when it reads the config. In a shell script it is the other way round:tmux display -pgives you the value of that moment, and it will not update by itself. - Inside tmux’s own prompt you drop the
-p. AfterCtrl-b :you typedisplay '#{pane_current_path}'and the answer appears in the status line for a moment, because there is no shell to print it to.
Step 6 of 9: Layouts, and typing in every pane at once
After a few splits and some dragging, the panes in a window rarely look the way you meant them to. tmux has five preset layouts that rearrange all panes in one go, and you met the key for them in the beginners guide: Ctrl-b Space cycles through them. If you know which one you want, you can jump straight to it:
Ctrl-b Alt-1:even-horizontal, all panes side by side, equally wide.Ctrl-b Alt-2:even-vertical, all panes stacked, equally high.Ctrl-b Alt-3:main-horizontal, one big pane on top and the rest in a row underneath.Ctrl-b Alt-4:main-vertical, one big pane on the left and the rest in a column on the right.Ctrl-b Alt-5:tiled, a grid that is as even as the number of panes allows.
Three panes after Ctrl-b Alt-4. The big pane on the left takes the default 80 columns, and the other two share the narrow strip that is left, one above the other. The blue border marks the active pane, from pane-active-border-style in the config. In a small window like this one the right column gets cramped, and main-pane-width, a little further down, fixes that.
tmux 3.8 also binds Ctrl-b Alt-6 and Ctrl-b Alt-7 to mirrored versions of the two main layouts, with the big pane at the bottom or on the right. On a Mac the Alt key is Option, and your terminal has to send it as Meta for these keys to reach tmux (in iTerm2 and Ghostty that is a setting for the left or right Option key). If Alt-1 types a strange character instead, that setting is why.
The same layouts work as a command, which is the version I would use in scripts and in the prompt:
tmux select-layout tiled
tmux select-layout main-vertical
The main layouts make the big pane 80 columns wide or 24 rows high by default. Two options change that, and they accept a percentage as well as a number of cells:
setw -g main-pane-width 50%
setw -g main-pane-height 60%
The new size applies the next time you pick a main layout, so press Ctrl-b Alt-4 again after setting it. And when your panes are fine but just uneven, Ctrl-b E (capital E) spreads them out evenly without changing their arrangement. It runs select-layout -E, and I find it the least disruptive of these keys because nothing moves to a different spot.
When none of the presets fits, you can build a layout by hand, resize it until it looks right and then save it as a string. tmux describes the current layout of every window in a format variable:
tmux list-windows -F '#{window_index} #{window_layout}'
On tmux 3.8 the layout comes out as a line of JSON. For a window with a narrow pane on the left and two stacked panes on the right, it starts like this:
{"V":2,"L":{"t":"h","w":120,"h":40,"x":0,"y":0,"c":[{"t":"p","w":30,"h":40, ...
This is the full string for a window of 92 by 13 cells with three panes. You never have to read it, but it is less cryptic than it looks. "t":"h" at the top means the window is split side by side, and its "c" list holds the two halves: a pane 46 columns wide, and a "t":"v" part that splits the right half into two panes of 45 by 6, one above the other. "w", "h", "x" and "y" are the size and position of each part, "i" is the pane index, and "a":true marks the active pane. The pane was zoomed with Ctrl-b z to give the long line room, which is the Z in the tab, and the layout still describes the window as it is without the zoom.
Older versions print a shorter string that starts with a checksum, something like bb62,120x40,0,0{30x40,0,0,0,...}. You do not need to read either of them. Copy the whole value and hand it back to select-layout later, in quotes:
tmux select-layout '{"V":2,"L":{ ... the whole line you copied ... }}'
On tmux 3.8 the round trip works: save the layout, switch to tiled, apply the saved string and you get the exact pane sizes back. 3.8 also accepts the old checksum format. Two conditions apply. The window needs the same number of panes as when you saved it, and the string has to be passed in single quotes, because the JSON is full of double quotes. Put it in a script or a bind line and you have your own preset.
Check that it worked: tmux list-panes -F '#{pane_index} #{pane_width}x#{pane_height}' before and after the restore prints the same sizes.
Sometimes you want to type the same thing in several places: the same update command on three servers, say, or the same git pull in three checkouts. synchronize-panes sends every key you type to all panes in the current window. The beginners guide mentioned it as a command. The config in this guide puts it on a key and shows its state in the status bar:
bind S setw synchronize-panes \; display-message "synchronize-panes #{?pane_synchronized,on,off}"
setw synchronize-panes without on or off flips the option, so Ctrl-b S turns it on and the next Ctrl-b S turns it off. The message after the \; uses a conditional to tell you which of the two just happened, and the SYNC label comes from #{?pane_synchronized,...} in status-right. Forgetting that it is on is how you run a command in four places by accident, which is why I wanted both.
To try it, split a window into three panes, press Ctrl-b S and type a command once:
echo $((6*7))
Each of the three panes shows echo $((6*7)) with 42 under it. The yellow SYNC on the right of the status bar reminds you that whatever you type now goes everywhere. In real use each pane would be an SSH session to a different server, and the command would be an update or a status check.
Check that it worked: the status bar shows SYNC, and tmux display -p '#{pane_synchronized}' prints 1. Press Ctrl-b S again and the label disappears.
The beginners guide already warned about this: synchronize-panes types into every pane of the window, including the one you forgot was there, the one with an editor open and the one where a password prompt is waiting. Look for the SYNC label before you paste anything, and turn it off as soon as you are done. If you do not have the binding, this always works:
tmux setw synchronize-panes off
It is a window option, so it only affects the window where you turned it on. Other windows in the same session keep their normal, one-pane-at-a-time keyboard.
If you always end up pressing Ctrl-b Alt-5 after a split, let tmux do it. Hooks run a command after something happens, and after-split-window fires after every split:
tmux set-hook -g after-split-window 'select-layout tiled'
In ~/.tmux.conf it is the same line without the leading tmux. The -g makes it global, so it applies to every session.
Nobody touched a layout key here. Each pane ran echo pane with its own number, so you can tell them apart. Without the hook, splitting the same pane three times gives you ever thinner slices.
Check that it worked: list the global hooks and look for the line.
tmux show-hooks -g | grep after-split
It prints after-split-window[0] select-layout tiled. The [0] is there because a hook can hold more than one command. To remove it again:
tmux set-hook -gu after-split-window
After that the same grep prints only the bare name after-split-window, which means the hook exists but is empty. Be aware that this hook is global and strict: every split, in every window, gets tiled, including the window where you carefully set up a big editor and a small terminal. If that annoys you, keep the hook out of the config and set it only in the sessions where you want it, without the -g.
Both checks in one terminal: with the hook set, the grep finds after-split-window[0] select-layout tiled, and after -gu only the bare name is left. The [0] also tells you that one hook can hold a list of commands. set-hook -ga appends another one, which shows up as [1], and -gu clears the whole list in one go.
Step 7 of 9: Naming, ordering and moving windows
Window names are what you read in the status bar all day, so they are worth a moment. By default tmux names a window after the program running in it. That is the automatic-rename option, and it is on. Start vim and the tab says vim, quit and it says bash or zsh again. The text comes from automatic-rename-format, which on tmux 3.8 is the current command, with [tmux] while the pane is in copy mode and [dead] when its program has ended:
tmux show -gv automatic-rename-format
It is a format, so you can change it. A common variant shows the folder instead of the program:
setw -g automatic-rename-format "#{b:pane_current_path}"
b: keeps only the last part of the path, so ~/site shows as site. I prefer names I choose myself, and tmux makes that easy: when you rename a window with Ctrl-b ,, tmux switches automatic-rename off for that window only, so your name sticks and the other windows keep following their programs. If you never want automatic names, turn it off globally with setw -g automatic-rename off.
Programs can also rename a window themselves, with an escape sequence. allow-rename decides whether tmux listens, and it is off by default. I would leave it off. With it on, a shell theme that sets the title on every prompt quietly overwrites the names you gave your windows.
Check that it worked: tmux show -w automatic-rename in a window you renamed prints automatic-rename off, and tmux show -gv allow-rename prints off.
With renumber-windows on from the config, closing a window closes the gap. To change the order on purpose, swap-window trades two windows:
# swap the current window with the one to its left, and stay on it
tmux swap-window -d -t -1
# the same idea as keys: Ctrl-b < and Ctrl-b > move the window
bind -r < swap-window -d -t -1
bind -r > swap-window -d -t +1
The -d reads the wrong way round. On tmux 3.8, without it you stay at the old position and end up looking at the other window. With it, you go along with the window you moved. -t -1 and -t +1 are relative to the current window, and they wrap around at the ends of the list. The -r lets you press < a few times in a row after one prefix, the same repeat trick as the resize keys. One warning: tmux 3.8 already uses Ctrl-b < and Ctrl-b > for the window and pane menus (the same menus you get with a right click, see the next section). These two lines replace them, so pick other keys if you use those menus.
Ctrl-b . moves the current window to another index. It asks for the target at the bottom of the screen: type 9 and the window becomes number 9. If that number is taken, tmux answers index in use and nothing moves. After moving things around, tmux move-window -r renumbers all windows of the session from base-index up.
A window can also go to a different session. The trailing colon means “the next free index in that session”:
tmux move-window -t notes:
The current window leaves this session and appears in the session notes. link-window does the same without removing it, so one window lives in two sessions at once. Both sessions show one and the same window, so what you type in one shows up in the other. tmux list-windows -a -F '#S:#I #W #{window_linked_sessions}' prints a 2 behind a window that is linked into two sessions. tmux unlink-window removes it from the current session again, and the other session keeps it. For panes there is the pair from the beginners guide: Ctrl-b ! breaks a pane out into its own window, and tmux join-pane -s :2 pulls window 2 back in as a pane of the current one.
Check that it worked: tmux list-windows -a -F '#S:#I #W' lists every window on the server with its session, so you see where a moved or linked window ended up.
tmux can also watch a window for you. monitor-activity flags a window when something is printed in it while you look elsewhere. monitor-silence does the opposite: it flags a window when nothing has been printed for a number of seconds, which is a decent hint that a long build or download has stopped:
tmux setw monitor-activity on
tmux setw monitor-silence 30
Both are window options, and I set them per window from the command line rather than in the config. Activity in every window is mostly noise. In the default status bar a flagged window gets a # for activity or a ~ for silence behind its name, plus a ! for a bell, and the tab is drawn in reverse colours. The window formats in this guide’s config leave the flags out, so there you only get the reverse colours. To see the symbols as well, add #F to both window formats:
set -g window-status-format " #I:#W#F "
For this screenshot both window formats got #F, and monitor-activity went on for every window with setw -g. 1:editor* is the current window, and the * is its flag. 3:logs#- has two flags: # because output arrived while you were looking at another window, and - because it is the last window you were in, the one last-window goes back to. Its tab is also drawn in reverse colours, which is all you would see without #F. 2:server printed nothing and has no flag.
Ctrl-b Alt-n jumps to the next window with an alert (activity, silence or a bell), and Ctrl-b Alt-p to the previous one.
Check that it worked: switch on monitor-activity in a window, run sleep 5; echo done there and switch to another window. When done prints, the tab changes, and Ctrl-b Alt-n takes you straight back.
Step 8 of 9: The mouse and customize mode
set -g mouse on was one line in the beginners config, and it does more than scrolling. tmux handles each mouse action with an ordinary key binding in the root table, so you can see exactly what it does:
tmux list-keys -T root | grep Mouse
On tmux 3.8 that list comes down to this:
- A click in a pane makes it the active pane. A click on a window name in the status bar switches to that window, and the scroll wheel over the status bar moves to the previous or next window.
- Dragging a pane border resizes the panes on both sides.
- Scrolling up in a pane enters copy mode, and scrolling back down to the bottom leaves it again.
- Dragging over text selects it in copy mode, and letting go copies it. Where the text ends up depends on
copy-commandandset-clipboard, as the copy mode section explains. - A double click copies a word, a triple click a whole line.
- A middle click pastes the most recent tmux buffer.
- A right click on a pane opens a menu with things like split, zoom, swap and kill. A right click on a window name opens a window menu with rename, swap and kill.
When the program in a pane asks for the mouse itself, as vim or htop can, tmux passes the clicks and the wheel on to that program instead.
The trade-off is your terminal’s own selection. With mouse mode on, tmux takes the drag, so the selection you are used to from your terminal stops working inside tmux, and a selection that spans two panes side by side is impossible anyway. Most terminals have a modifier key that you hold while dragging to bypass tmux and select the old way. In many it is Shift, but it differs per terminal, so look it up in your terminal’s documentation. If the mouse keeps getting in your way, it is a session option, and tmux set mouse off turns it off in the current session only.
Check that it worked: right-click a window name in the status bar. A small menu with the window’s number and name as its title opens next to it, and Escape closes it.
Options are the other thing that is hard to keep in your head. tmux has a few hundred, spread over server, session, window and pane levels. Customize mode is a browser for all of them. Press Ctrl-b C (capital C, tmux 3.2 and later) and the pane fills with a tree: Server Options, Session Options, Window & Pane Options, the session and window hooks, the global and session environment, and one entry per key table, such as prefix, root and copy-mode-vi.
Move with the arrow keys, and press Right (or +) to open a group and Left (or -) to close it. Every option shows with its current value next to the name, so opening a group is the quickest way to see what tmux really has.
This is the Session Options group, opened with Right. Each line is one option and its value, in alphabetical order: activity-action: other first, then base-index: 1 (the 1 comes from the config), then default-command and the rest. The + in front of a line means you can open it for details. A box under the list describes the option the cursor is on, says at which level it is set and shows its value. v hides or shows that box.
Here the cursor is on base-index: 1, and the box tells you what the option does, that it is a session option, its current value and the default. Those last two lines are a quick test for any line in your config. Option value: 1 next to The default is: 0 means the line from the config did something. When both show the same value, the line only repeats the default and you could drop it.
To change a value, put the cursor on it and press Enter. A prompt opens with the current value. Type the new one and press Enter again. Note what it changes: on a session option, Enter sets it for the current session, and the line then reads something like base-index: (session work) 1. S sets the global value instead, and d puts an option back to its default. Ctrl-s searches by name, and f filters the tree with a format, for example #{m:*mouse*,#{option_name}} to show only options with mouse in the name. c clears the filter, F1 lists the keys and q leaves the mode.
I like customize mode for discovering options. You browse what your version really has, each option comes with a short description, and the value you see is the live one, so you know whether a setting was picked up. I find that safer than pasting lines from the internet that were written for an older tmux.
Changes you make there are not saved. Customize mode sets options on the running server, the same as typing set at the Ctrl-b : prompt, and nothing is written to ~/.tmux.conf. After a restart of the server the change is gone. When you find a setting you want to keep, write the line into the file yourself and reload with Ctrl-b r.
Check that it worked: change an option in customize mode, leave it with q and run tmux show -v with the option name. It prints the new value. grep the option name in ~/.tmux.conf and the file still has the old line, or none.
Step 9 of 9: What comes next
With this config tmux fits my hands a lot better. Copying from a log takes a few keys, the status bar tells me when the prefix is pending or the panes are linked, and I understand every line in the file because I added them one block at a time. None of these changes is big on its own, but I notice them every day.
The next guide puts this config to work: tmux in daily use: sessions, popups, plugins and work over SSH. It adds popups and menus, a script that builds a whole workspace with one command, plugins that bring your sessions back after a reboot, and tmux inside tmux on a remote machine. The advanced cheat sheet PDF at the top of this page covers both guides, so print it once and keep it next to the keyboard.
