My tmux Notes
These notes are my personal cheat sheet for using tmux.
Whilst my configuration changes some key bindings, the ones below are the defaults in case I need to use someone else’s session on a remote server.
Sessions
A tmux session is an ‘environment’ which contains one or more windows and those windows contain one of more panes.
You can detatch from and reattach to tmux sessions. When you detach from a session it continues to run (unlike if you terminate it) so you can reattach to it later and it will be as you left it (the windows and panes will be the same along with whatever you left running in them).
Commands
Terminal
Starting a session | tmux or tmux new |
Start a named session | tmux new -s [session-name] |
List running sessions | tmux list-sessions or tmux ls |
Attach to a session | tmux attach-session -t [session-name] |
Within tmux
Detach from a session | Shortcut+d |
Show a list of sessions | Shortcut+s |
Rename a session | Shortcut+$ |
Display help | Shortcut+? |
Notes
A session has a status bar which usually shows:
- The session name in brackets. By default they are numbered, starting with zero:
[0]
. - The window number and process name (or program name if you are running one). Window numbers can be configured to be indexed from
1
rather than0
. An example is0:zsh*
. The asterisk denotes that this is the visible window. Each time a new window is created its number and name will be added to the status bar. - The host name is shown on the right along with the date and time.
To close a session (not detatch from it), close all of the panes in all of the windows or kill all of the windows. You will see [exited]
in the terminal window which confirms that the session was closed and not detached from.
When you detach from a session the terminal window will show [detached ...]
with details about the session you have detached from.
The sessions list can be expanded to show windows (and the windows list can be collapsed to show sessions) using the left and right arrow keys.
Windows
A tmux session can contain one or more windows.
Commands
Create a new window in a session | Shortcut+c |
Move to next window | Shortcut+n |
Move to previous window | Shortcut+p |
Move to window n (0 to 9) |
Shortcut+[n] |
Show a list of windows | Shortcut+w |
Rename current window | Shortcut+, |
Kill current window | Shortcut+& |
Notes
The list of windows also shows windows in other running sessions and allows you to switch to them.
Panes
Panes are independent instances of command lines within a window.
Commands
Split horizontally | Shortcut+" |
Split vertically | Shortcut+% |
Close a pane | Shortcut+x |
Move between panes | Shortcut+[cursor-key] |
Show pane numbers | Shortcut+q |
Move between panes in order | Shortcut+o |
Notes
The split keys are not particularly memorable and in my own config they have been changed to v
and b
to mirror the keys used in Sway.