--- title: Terminal Multiplexer [TMUX] description: draft: false tags: - tools author: TrudeEH showToc: true --- ## Overview `tmux` is a multiplexer that, among other things, is able to: - Preserve a terminal session if it is closed or lost. - Access an old session from a new terminal window. - Connect to a remote session and save its state once disconnected. - Split the terminal into multiple tabs and panes. ### Components - **Sessions** (Only one `tmux` session can be used at a time. Similar to workspaces.) - **Windows** (A session contains windows. These behave like tabs in other programs.) - **Panes** (A split in the window, each with its own terminal instance.)  ## [Commands](https://tmuxcheatsheet.com/) To start a command, press the `PREFIX KEY
`. The default is `ctrl b`, but my configuration uses `ctrl s` instead. |Command|Description| |---|---| |`
c`|Create a new window.| |`
[0-9]`|Switch to [0-9] window.| |`
n`|Switch to the next window.| |`
p`|Switch to the previous window.| |`
&`|Close a window.| |`
%`|Split the pane horizontally.| |`
"`|Split the pane vertically.| |`
[ARROW KEYS]`|Switch active pane.| |`
[{,}]`|Move the selected pane.| |`
q`|Toggle pane numbers. Then press a number to select that pane as the active one.| |`
z`|Expand the selected pane to take up the whole window.| |`
!`|Turn the selected pane into a window.| |`
x`|Close a pane.|
|`tmux`|Create and attach to a new session.|
|`tmux new -s s`|List active sessions from tmux.|
|` w`|Preview windows for each session.|
|`tmux attach`|Attach to last session.|
|`tmux attach -t :`|Command mode.|
> With `mouse-mode` enabled, you can use the cursor to navigate through `tmux`. To select text (to copy, for example), use `shift [drag]`.
## Configuration
Configure `tmux` using the `$HOME/.tmux.conf` config file.
For example:
```Shell
# easy reload config
bind-key r source-file ~/.tmux.conf \; display-message "~/.tmux.conf reloaded."
# set window split
bind-key v split-window -h
bind-key b split-window
# default window title colors
set-window-option -g window-status-style fg=colour244,bg=default,dim
# active window title colors
set-window-option -g window-status-current-style fg=orange,bg=default,bright
# pane border
set-option -g pane-border-style fg=colour236
set-option -g pane-active-border-style fg=orange # orange
# message text
set-option -g message-style bg=colour235,fg=orange
# pane number display
set-option -g display-panes-active-colour blue
set-option -g display-panes-colour orange
# clock
set-window-option -g clock-mode-colour orange
# Leader Key
set -g prefix C-a
bind-key C-a last-window
# Start index at 1
set -g base-index 1
# Allows for faster key repetition
set -s escape-time 50
# Rather than constraining window size to the maximum size of any client
# connected to the *session*, constrain window size to the maximum size of any
# client connected to *that window*. Much more reasonable.
setw -g aggressive-resize on
# Allows us to use C-a a