/

Tmux Cheat Sheet

A short cheat sheet of tmux shortcuts I keep forgetting, mostly written down for myself.

All shortcuts below start with the prefix key, which by default is Ctrl+b. So prefix + c means: press Ctrl+b, release, then press c.

Sessions

A session is a collection of windows. This is handy to group your work, e.g. one session per project.

ShortcutDescription
tmux new -s <name>Create a new named session
tmux attach -t <name>Attach to an existing session
tmux kill-session -t <name>Kill a session
tmux lsList all sessions
prefix + dDetach from the current session

Creating a session while already inside one

If you’re already inside a tmux session and want to start another one, avoid nesting tmux inside tmux (running tmux new -s ... directly), since that causes prefix-key conflicts. Instead, create the new session in the background and switch to it:

ShortcutDescription
tmux new-session -d -s <name>Create a new session in the background, without attaching to it
prefix + sShow an interactive list of sessions to switch between
tmux switch-client -t <name>Switch directly to a session by name

Windows

A window is like a tab in your terminal, it takes up the whole screen and can contain multiple panes.

ShortcutDescription
prefix + cCreate a new window
prefix + ,Rename the current window
prefix + nGo to the next window
prefix + pGo to the previous window
prefix + 0-9Go to window by number

Panes

Panes let you split a window into multiple sections, so you can run several things side by side.

ShortcutDescription
prefix + %Split pane vertically
prefix + "Split pane horizontally
prefix + oSwitch to the next pane
prefix + arrow keySwitch to the pane in that direction
prefix + xClose the current pane

Copy mode

I don’t use this often, but it’s handy to know: copy mode lets you scroll back through the pane’s history and copy text.

ShortcutDescription
prefix + [Enter copy mode (use arrow keys or Page Up/Page Down to scroll)
SpaceStart a selection (in copy mode)
EnterCopy the selection and exit copy mode
prefix + ]Paste the last copied text
qQuit copy mode

Configuration: starting index at 1

By default, tmux numbers windows and panes starting at 0, which doesn’t line up with the 1 key on my keyboard. I like to start counting at 1 instead. You can change this by creating (or editing) ~/.tmux.conf:

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

# Renumber windows automatically when one is closed
set -g renumber-windows on

If tmux is already running, reload the config without restarting your session:

tmux source-file ~/.tmux.conf

Or, from inside tmux itself: prefix + : and then type source-file ~/.tmux.conf.

That’s it, a small cheat sheet that covers most of what I use tmux for on a daily basis.