# TMux
TMux (Terminal Multiplexer) is a terminal ([[Shell]]) application that allows running multiple terminal sessions within a single window. It enables splitting the terminal into panes, creating multiple windows, and most importantly, detaching sessions that continue running in the background.
TMux is essential for remote work, long-running processes, and organizing complex terminal workflows.
## Key Concepts
- **Session**: A collection of windows managed by tmux
- **Window**: A single screen within a session (like browser tabs)
- **Pane**: A subdivision of a window (split view)
- **Prefix key**: The key combination to trigger tmux commands (default: `Ctrl+b`)
## Why Use TMux
- **Persistent sessions**: Detach and reattach without losing work
- **Remote resilience**: SSH disconnection doesn't kill processes
- **Workspace organization**: Multiple projects in separate sessions
- **Split views**: See multiple terminals simultaneously
- **Pair programming**: Share sessions with collaborators
## Essential Commands
### Session Management
| Command | Description |
| --------------------------- | -------------------- |
| `tmux new -s name` | Create named session |
| `tmux ls` | List sessions |
| `tmux attach -t name` | Attach to session |
| `tmux kill-session -t name` | Kill session |
### Inside TMux (prefix = `Ctrl+b`)
| Keys | Action |
| -------------- | ----------------------- |
| `prefix d` | Detach from session |
| `prefix c` | Create new window |
| `prefix n/p` | Next/previous window |
| `prefix 0-9` | Switch to window number |
| `prefix %` | Split pane vertically |
| `prefix "` | Split pane horizontally |
| `prefix arrow` | Navigate panes |
| `prefix z` | Toggle pane zoom |
| `prefix x` | Kill current pane |
| `prefix [` | Enter copy mode |
| `prefix ?` | List all keybindings |
## Configuration
TMux is configured via `~/.tmux.conf`:
```bash
# Change prefix to Ctrl+a
set -g prefix C-a
unbind C-b
# Enable mouse support
set -g mouse on
# Start windows at 1, not 0
set -g base-index 1
# Faster key repetition
set -s escape-time 0
# Reload config
bind r source-file ~/.tmux.conf \; display "Reloaded!"
```
## Popular Plugins (via TPM)
- **tmux-resurrect**: Save and restore sessions
- **tmux-continuum**: Automatic session saving
- **tmux-sensible**: Sensible default settings
- **tmux-yank**: Copy to system clipboard
## Common Workflows
### Development Setup
```bash
tmux new -s dev
# Window 1: Editor (vim/nvim)
# Window 2: Server/build process
# Window 3: Git operations
# Window 4: Tests
```
### Remote Server Work
```bash
ssh server
tmux attach || tmux new -s work
# Work safely - disconnection won't kill processes
```
## References
- https://github.com/tmux/tmux
- https://tmux.github.io/
- https://en.wikipedia.org/wiki/Tmux
## Related
- [[Shell]]
- [[Bash]]
- [[Zsh (Z Shell)]]
- [[Command Line Interface (CLI)]]
- [[Terminal User Interface (TUI)]]
- [[Terminal Multiplexers]]
- [[Zellij]]
- [[tmux-ide]]