The tmux field guide
tmux is a free terminal tool that keeps your work running in the background and splits one window into several. Every shortcut starts the same way: press Ctrl+b, let go, then press one more key.
Updated
Practice here first.
Press a button and watch the screen change. With a keyboard, click the screen and use the real keys.
Two panes are open in the tab named code.
The violet outline shows which pane you are typing in.
Three levels, one inside the next.
Once you can see these, every shortcut below makes sense.
Session: app
Tab 1: code
code
server
Tab 2: git
git
- Session
- One whole project. It keeps running in the background when you close the terminal app.
- Tab
- tmux calls it a window. A full screen inside the session. The names along the bottom bar are your tabs.
- Pane
- One terminal. A tab can hold one pane or several side by side.
On the bottom bar, the violet block is the session you are in, the highlighted name is the tab you are on, and the right side is the date and time.
Panes
Two or more terminals in one tab. Use them to watch two things at once, like your code on the left and the server log on the right.
- Ctrl+bthen|
- Ctrl+bthen-
- Ctrl+bthenhjkl
Move to another pane
h is left, j is down, k is up, l is right. The arrow keys work in stock tmux, and so does a click once the mouse is on.
Uses the settings below - Ctrl+bthenz
Make one pane fill the screen
The same keys bring the others back.
- Ctrl+bthenholdCtrland tap anarrow
Resize a pane
Or drag the dividing line with the mouse.
- Ctrl+bthenq
Show a number on each pane
Press the number while it shows to jump there.
- Ctrl+bthen}or{
Swap this pane with its neighbor
- Ctrl+bthenSpace
Try the next ready-made layout
Even columns, even rows, one big and the rest small.
- Ctrl+bthen!
Move this pane into its own tab
Close a pane
tmux asks first. Press y to confirm.
exitorCtrl+bthenx
Tabs
tmux calls them windows. Each one is a full screen inside the session. Open a new one for a separate job, like git.
- Ctrl+bthenc
New tab
- Ctrl+bthennorp
Next tab, previous tab
- Ctrl+bthen1to9
Jump to a tab by its number
Stock tmux counts from 0. The settings below start at 1 to match the keyboard.
- Ctrl+bthen,
Rename this tab
- Ctrl+bthenw
See every session and tab in a list
Arrow to one, press Enter to go there.
- Ctrl+bthenf
Find a tab by name
- Ctrl+bthen&
Close a tab and everything in it
Press y to confirm.
Sessions
One session per project. A session keeps working after you step out of it, which is the main reason to use tmux at all.
- Ctrl+bthend
Step out and leave it running
This is called detaching. Your server and anything else in the session keep going.
- Ctrl+bthens
Switch to another session
- Ctrl+bthen)or(
Next session, previous session
- Ctrl+bthen$
Rename this session
Start a new named session
tmux new -s appList the sessions that are running
tmux lsGo back into a session
tmux attach -t appEnd a session for good
tmux kill-session -t app
Scrolling and copying
Each pane keeps its own history. The settings below raise it to 50,000 lines and turn the mouse on.
- scroll
Scroll up through old output
With the mouse on, the trackpad or wheel does it. Press q to drop back to the bottom.
- Ctrl+bthen[
Scroll with the keyboard
Then use the arrows or Page Up. Press q to leave.
- Ctrl+rsearches up,Ctrl+sdown
Search the old output
While scrolled back. If your editor is set to vi, the keys are ? and / in its place.
- dragthen paste withCtrl+bthen]
Copy text inside tmux
Drag across it with the mouse on. It copies when you let go.
- fnorOptionthenCmd+C
Copy text the normal Mac way
Hold fn in Apple Terminal, or Option in iTerm2, while you drag.
Help and extras
The handful of keys that make the rest easier to find.
- Ctrl+bthen?
List every shortcut tmux has
Press q to close the list.
- Ctrl+bthen:
Type a tmux command by name
Type into every pane at once
Enter it after Ctrl+b then the colon key. Use off to stop.
setw synchronize-panes on- Ctrl+bthenr
Reload the settings after editing them
Uses the settings below - Ctrl+bthent
Show a big clock in the pane
If something feels stuck
Almost every tmux scare is one of these five.
- q
Typing does nothing
A counter like [12/340] in the top right corner means you are scrolled back.
- Ctrl+bthenz
One pane fills the screen and the rest are gone
It is zoomed.
You closed the terminal app by mistake
Nothing is lost. Open it again and go back in.
tmux attach- Esc
You pressed Ctrl+b and changed your mind
You restarted the computer
A restart does end every session. Start the session again.
tmux new -s app
The settings behind this guide.
Stock tmux works without any of this. These lines make the splits easier to remember, turn the mouse on, and dress the bottom bar.
- Install tmux. On a Mac with Homebrew:
brew install tmux - Save the file. Put these lines in a file named
.tmux.confin your home folder. - Start a session.
tmux new -s app
# ~/.tmux.conf
# Reload after edits: Ctrl+b then r
# Mouse: click panes, drag borders, scroll with the trackpad
set -g mouse on
# Colors and a long scrollback
set -g default-terminal "tmux-256color"
set -g history-limit 50000
# Tabs and panes count from 1, like the keyboard row
set -g base-index 1
setw -g pane-base-index 1
set -g renumber-windows on
# Easier splits, opening in the folder you are already in
bind | split-window -h -c "#{pane_current_path}"
bind - split-window -v -c "#{pane_current_path}"
bind c new-window -c "#{pane_current_path}"
# Move between panes with h j k l
bind h select-pane -L
bind j select-pane -D
bind k select-pane -U
bind l select-pane -R
# Reload this file
bind r source-file ~/.tmux.conf \; display-message "tmux config reloaded"
# Status bar: session on the left, tabs, time on the right
set -g status-style "bg=#141424,fg=#e0e0e0"
set -g status-left-length 30
set -g status-left "#[bg=#7c3aed,fg=#ffffff,bold] #S #[default] "
set -g status-right "#[fg=#c4b5fd]%a %b %d %I:%M %p "
setw -g window-status-current-style "bg=#c4b5fd,fg=#0b0b14,bold"
setw -g window-status-current-format " #I:#W "
setw -g window-status-format " #I:#W "
set -g pane-active-border-style "fg=#a78bfa"
# No delay after Esc
set -sg escape-time 10
Checked on tmux 3.7 on macOS.
How we run a build in it.
Every project at Klema Labs lives in its own tmux session, laid out the same way.
One session per project, named after the project.
Switching projects is switching sessions. Nothing from one build leaks into another.
The first tab is split: code on the left, the server on the right.
The server log is always in view, so an error shows up the moment it happens.
A second tab is kept for git.
Commits and pushes happen away from the running server, in the same session.
Sessions are left running between sittings.
Closing the terminal app does not stop the server. Going back in puts every pane where it was.
Have software you want built?
We design and ship custom platforms, portals and internal tools on fixed-price milestones. You own the code.