Ctrl K

tmux Sessions, Windows, and Panes

Keyboard driven terminal tool for managing multiple contexts in parallel. Daily routine for sessions, windows, and panes.

tmux organizes terminal work in three levels: sessions (top-level workspaces), windows (tabs inside a session), and panes (splits inside a window).

Quick reference

# Prefix: Ctrl+b

# Sessions from the shell
tmux ls         # list sessions
tmux attach     # attach to session

# Sessions from inside tmux
Ctrl+b d                      # detach (session keeps running)
Ctrl+b s                      # list and choose session
Ctrl+b : new-session -s x     # create session without detaching
Ctrl+b : switch-client -t x   # switch to session x

# Windows
Ctrl+b c        # new window
Ctrl+b n        # next window
Ctrl+b p        # previous window
Ctrl+b w        # list windows
Ctrl+b &        # kill window

# Panes
Ctrl+b %        # split left/right
Ctrl+b "        # split top/bottom
Ctrl+b arrows   # move between panes
Ctrl+b x        # kill pane
Ctrl+b z        # zoom pane
Ctrl+b !        # pane to new window
Ctrl+b Space    # cycle layouts

# Copy / scroll
Ctrl+b [        # copy mode
Ctrl+b ]        # paste

Config (~/.tmux.conf)

In addition to the default cases, these two lines provide useful customization. Open the tmux.conf to set these:

set -g mouse on
set -g history-limit 100000

Default prefix

All tmux shortcuts start with the prefix key. Press it, release, then press the next key.

Ctrl+b

Sessions

Sessions are top-level workspaces. They keep running even if you close the terminal, until you kill them or reboot.

From the shell (outside tmux):

tmux                      # new unnamed session, named 0 by default
tmux new -s ml            # new named session
# -s: session name
tmux ls                   # list sessions
tmux attach -t ml         # attach to session
# -t: target
tmux kill-session -t ml   # kill a session
tmux kill-server          # kill the whole tmux server

If you started with just tmux the session is called 0. To rename it afterwards:

tmux rename-session mysession   # from the shell while attached
Ctrl+b $                        # from inside tmux

From inside a running tmux session:

Ctrl+b d   # detach and returns you to the shell, session keeps running

Session navigation from inside tmux

These are all used from inside a running tmux session.

Ctrl+b s                    # open interactive session list, choose with arrows + Enter
Ctrl+b : new-session -s x   # create a new named session without detaching
# -s: session name
Ctrl+b : switch-client -t x # jump to an existing session by name

Ctrl+b : opens the tmux command prompt at the bottom of the screen. Type the command after the colon and press Enter.

Windows

Windows are tabs inside a session.

Ctrl+b c   # new window
Ctrl+b n   # next window
Ctrl+b p   # previous window
Ctrl+b 0   # go to window 0 (1, 2, ... also work)
Ctrl+b w   # list windows and choose one
Ctrl+b ,   # rename current window
Ctrl+b &   # kill current window

Panes

Panes are splits inside a window.

Ctrl+b %          # split left/right
Ctrl+b "          # split top/bottom
Ctrl+b Left/Right/Up/Down   # move between panes
Ctrl+b o          # move to next pane
Ctrl+b ;          # jump back to previous pane
Ctrl+b q          # show pane numbers briefly
Ctrl+b x          # kill current pane
Ctrl+b !          # turn pane into its own window
Ctrl+b z          # zoom pane full-screen (toggle)
Ctrl+b Space      # cycle pane layouts
Ctrl+b Ctrl+Left/Right/Up/Down  # resize pane
exit              # close pane from shell
Ctrl+d            # close pane from shell

Copy mode and scrollback

Scroll with arrow keys, PageUp, PageDown.

Ctrl+b [   # enter copy mode
Ctrl+b ]   # paste copied text

Mouse

Mouse support is enabled via set -g mouse on.

  • Click a pane to select it
  • Click a window in the status bar to switch to it
  • Scroll with the mouse wheel or touchpad
  • Drag pane borders to resize panes

Help and command prompt

Ctrl+b ?      # show all key bindings
Ctrl+b :      # open tmux command prompt
Ctrl+b Ctrl+b # send literal Ctrl+b to program inside tmux