> ## Documentation Index
> Fetch the complete documentation index at: https://docs.americ.io.vn/llms.txt
> Use this file to discover all available pages before exploring further.

# tmux

> A terminal multiplexer.

<Info>
  Trigger using  `Ctrl + b` (*trigger*) then `:` to enter command mode (*cm*) or another hotkey
</Info>

## 1. Sessions

```bash theme={null}
# Start a new session
tmux
tmux new
tmux new-session

# Start a named session
tmux new -s mysession

# Attach to existing session, or create it if it doesn't exist
tmux new-session -A -s mysession

# List all sessions
tmux ls
tmux list-sessions

# Attach to last session
tmux a
tmux attach

# Attach to a named session
tmux a -t mysession
tmux attach-session -t mysession

# Kill a named session
tmux kill-session -t mysession

# Kill all sessions except the current one
tmux kill-session -a

# Kill all sessions except a named one
tmux kill-session -a -t mysession
```

| Shortcut       | Action                     |
| -------------- | -------------------------- |
| `Ctrl+b` , `$` | Rename current session     |
| `Ctrl+b` , `d` | Detach from session        |
| `Ctrl+b` , `s` | Show / switch all sessions |
| `Ctrl+b` , `(` | Move to previous session   |
| `Ctrl+b` , `)` | Move to next session       |
| `Ctrl+b` , `w` | Session and window preview |

***

## 2. Windows (Tabs)

```bash theme={null}
# Start a new session with a named window
tmux new -s mysession -n mywindow
```

| Shortcut           | Action                     |
| ------------------ | -------------------------- |
| `Ctrl+b` , `c`     | Create a new window        |
| `Ctrl+b` , `,`     | Rename current window      |
| `Ctrl+b` , `&`     | Close current window       |
| `Ctrl+b` , `w`     | List all windows           |
| `Ctrl+b` , `p`     | Previous window            |
| `Ctrl+b` , `n`     | Next window                |
| `Ctrl+b` , `0`–`9` | Switch to window by number |
| `Ctrl+b` , `l`     | Toggle last active window  |

```bash theme={null}
# Swap window positions (e.g. swap 2 and 1)
:swap-window -s 2 -t 1

# Move current window one position left
:swap-window -t -1

# Move window between sessions
:movew -s srcSession:0 -t targetSession:9

# Renumber windows to remove gaps
:move-window -r
```

***

## 3. Panes (Splits)

| Shortcut               | Action                                     |
| ---------------------- | ------------------------------------------ |
| `Ctrl+b` , `%`         | Split pane **vertically** (side by side)   |
| `Ctrl+b` , `"`         | Split pane **horizontally** (top / bottom) |
| `Ctrl+b` , `Arrow`     | Switch to pane in that direction           |
| `Ctrl+b` , `o`         | Switch to next pane                        |
| `Ctrl+b` , `;`         | Toggle last active pane                    |
| `Ctrl+b` , `q`         | Show pane numbers                          |
| `Ctrl+b` , `q` `0`–`9` | Switch to pane by number                   |
| `Ctrl+b` , `z`         | Toggle pane zoom (fullscreen)              |
| `Ctrl+b` , `!`         | Convert pane into its own window           |
| `Ctrl+b` , `x`         | Close current pane                         |
| `Ctrl+b` , `{`         | Move current pane left                     |
| `Ctrl+b` , `}`         | Move current pane right                    |
| `Ctrl+b` , `Spacebar`  | Toggle between pane layouts                |
| `Ctrl+b` , `Ctrl+↑/↓`  | Resize pane height                         |
| `Ctrl+b` , `Ctrl+←/→`  | Resize pane width                          |

```bash theme={null}
# Merge window 2 into window 1 as a pane
:join-pane -s 2 -t 1

# Move a specific pane between windows
:join-pane -s 2.1 -t 1.0

# Send same command to ALL panes (pair programming / multi-server)
:setw synchronize-panes
```

***

## 4. Copy Mode (Scrollback & Search)

```bash theme={null}
# Use vi-style keys in copy mode (recommended)
:setw -g mode-keys vi
```

| Shortcut          | Action                                 |
| ----------------- | -------------------------------------- |
| `Ctrl+b` , `[`    | Enter copy mode                        |
| `Ctrl+b` , `PgUp` | Enter copy mode and scroll up one page |
| `q`               | Quit copy mode                         |
| `g` / `G`         | Go to top / bottom                     |
| `↑` / `↓`         | Scroll up / down                       |
| `h` `j` `k` `l`   | Move cursor (vi-style)                 |
| `w` / `b`         | Move forward / backward one word       |
| `/`               | Search forward                         |
| `?`               | Search backward                        |
| `n` / `N`         | Next / previous search match           |
| `Spacebar`        | Start selection                        |
| `Enter`           | Copy selection                         |
| `Esc`             | Clear selection                        |
| `Ctrl+b` , `]`    | Paste buffer                           |

```bash theme={null}
# Show buffer contents
:show-buffer

# Copy entire visible pane to buffer
:capture-pane

# List all buffers
:list-buffers

# Choose buffer to paste from
:choose-buffer

# Save buffer to a file
:save-buffer buf.txt

# Delete a buffer
:delete-buffer -b 1
```

***

## 5. Config & Mouse

```bash theme={null}
# Enter tmux command mode (from inside tmux)
# Ctrl+b :

# Enable mouse support (click to select panes/windows, scroll)
:set mouse on

# Set an option for all sessions
:set -g OPTION

# Set an option for all windows
:setw -g OPTION
```

***

## 6. Help & Info

```bash theme={null}
# List all key bindings
tmux list-keys

# Show all sessions, windows, panes info
tmux info
```

| Shortcut       | Action                              |
| -------------- | ----------------------------------- |
| `Ctrl+b` , `?` | List all key bindings (inside tmux) |

***

## Quick Reference Summary

| Task                | Command / Shortcut            |
| ------------------- | ----------------------------- |
| New named session   | `tmux new -s <name>`          |
| Attach to session   | `tmux a -t <name>`            |
| Detach from session | `Ctrl+b` , `d`                |
| List sessions       | `tmux ls`                     |
| Kill session        | `tmux kill-session -t <name>` |
| New window          | `Ctrl+b` , `c`                |
| Switch window       | `Ctrl+b` , `0–9`              |
| Split vertical      | `Ctrl+b` , `%`                |
| Split horizontal    | `Ctrl+b` , `"`                |
| Switch pane         | `Ctrl+b` , `Arrow`            |
| Zoom pane           | `Ctrl+b` , `z`                |
| Close pane          | `Ctrl+b` , `x`                |
| Enter copy mode     | `Ctrl+b` , `[`                |
| Paste buffer        | `Ctrl+b` , `]`                |
| Enable mouse        | `:set mouse on`               |
| Key binding list    | `Ctrl+b` , `?`                |
