Skip to content

Latest commit

 

History

History
475 lines (322 loc) · 5.37 KB

File metadata and controls

475 lines (322 loc) · 5.37 KB

tmux cheat sheet

tmux lets you keep terminal sessions running, split windows, and reconnect later.

Default prefix key:

Ctrl + b

After pressing Ctrl + b, release both keys, then press the command key.


Sessions

Create a new session:

tmux

Create a named session:

tmux new -s myproject

List sessions:

tmux ls

Attach to a session:

tmux attach -t myproject

Detach from current session:

Ctrl + b, then d

Kill a session:

tmux kill-session -t myproject

Rename current session:

Ctrl + b, then $

Windows

A tmux window is like a terminal tab.

Create new window:

Ctrl + b, then c

Switch to next window:

Ctrl + b, then n

Switch to previous window:

Ctrl + b, then p

Switch to window by number:

Ctrl + b, then 0
Ctrl + b, then 1
Ctrl + b, then 2

Rename current window:

Ctrl + b, then ,

Close current window:

Ctrl + b, then &

Show window list:

Ctrl + b, then w

Panes

A tmux pane is a split inside a window.

Split vertically, left/right:

Ctrl + b, then %

Split horizontally, top/bottom:

Ctrl + b, then "

Move between panes:

Ctrl + b, then arrow key

Close current pane:

Ctrl + b, then x

Zoom current pane fullscreen:

Ctrl + b, then z

Resize pane:

Ctrl + b, then hold Ctrl + arrow key

Show pane numbers:

Ctrl + b, then q

Convert pane to new window:

Ctrl + b, then !

Copy and scroll

Enter scroll/copy mode:

Ctrl + b, then [

Move around:

Arrow keys
Page Up
Page Down

Quit copy mode:

q

Search in scrollback:

Ctrl + b, then [
/search-text
Enter

Useful commands inside tmux

Show all key bindings:

tmux list-keys

Show all sessions:

tmux list-sessions

Show all windows:

tmux list-windows

Show all panes:

tmux list-panes

Reload tmux config:

tmux source-file ~/.tmux.conf

Good daily workflow

For one project:

tmux new -s orderbuddy

Then use windows like this:

Window 1: editor
Window 2: dev server
Window 3: tests
Window 4: logs
Window 5: git

Example:

Ctrl + b, c    # new window
Ctrl + b, ,    # rename it

Names:

code
server
tests
logs
git

Detach when finished:

Ctrl + b, d

Later reconnect:

tmux attach -t orderbuddy

Recommended .tmux.conf

Create or edit:

nano ~/.tmux.conf

Add:

# Use mouse for pane selection, resizing, and scrolling
set -g mouse on

# Start window and pane numbering at 1
set -g base-index 1
setw -g pane-base-index 1

# Larger scrollback history
set -g history-limit 50000

# Better colors
set -g default-terminal "screen-256color"

# Reload config with Prefix + r
bind r source-file ~/.tmux.conf \; display-message "tmux config reloaded"

# Easier pane splitting
bind | split-window -h
bind - split-window -v

# Move between panes using vim-style keys
bind h select-pane -L
bind j select-pane -D
bind k select-pane -U
bind l select-pane -R

# Resize panes
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

Reload:

tmux source-file ~/.tmux.conf

Now you can use:

Ctrl + b, |
Ctrl + b, -
Ctrl + b, h/j/k/l
Ctrl + b, r

Best tips

Use named sessions. Instead of just running tmux, use:

tmux new -s appname

This makes it much easier to reconnect later.

Use one session per project. For example:

tmux new -s orderbuddy
tmux new -s ai-agent
tmux new -s firebase-test

Use tmux for long-running tasks:

npm run dev
npm test -- --watch
firebase emulators:start
docker compose up
tail -f app.log

Detach safely with:

Ctrl + b, d

Your commands keep running.

For AI coding agents, tmux is very useful. Put the agent in one pane, tests in another pane, logs in another pane.

Example layout:

+----------------------+----------------------+
| Claude / agent       | npm test --watch     |
|                      |                      |
+----------------------+----------------------+
| dev server logs      | git / terminal       |
+----------------------+----------------------+

Use zoom often:

Ctrl + b, z

This makes one pane fullscreen temporarily.


Common problems

tmux mouse scroll does not work

Add this to ~/.tmux.conf:

set -g mouse on

Reload:

tmux source-file ~/.tmux.conf

I forgot the session name

tmux ls

Then:

tmux attach -t session-name

Kill everything

tmux kill-server

Be careful. This closes all tmux sessions.

Prefix key is annoying

Some developers change prefix from Ctrl + b to Ctrl + a:

unbind C-b
set -g prefix C-a
bind C-a send-prefix

Then use:

Ctrl + a

instead of:

Ctrl + b

My suggested beginner setup

Start with only these commands:

Ctrl + b, c      new window
Ctrl + b, n      next window
Ctrl + b, p      previous window
Ctrl + b, %      vertical split
Ctrl + b, "      horizontal split
Ctrl + b, arrow  move pane
Ctrl + b, z      zoom pane
Ctrl + b, d      detach

That is enough for 90% of daily use.