> For the complete documentation index, see [llms.txt](https://imarslo.gitbook.io/book/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://imarslo.gitbook.io/book/awesomeshell/tmux/cheatsheet.md).

# cheatsheet

* [files](#files)
  * [alias](#alias)
* [sessions](#sessions)
  * [linux commands](#linux-commands)
  * [tmux commands](#tmux-commands)
  * [shortcuts](#shortcuts)
* [windows](#windows)
  * [shortcuts for windows](#shortcuts-for-windows)
  * [tmux commands for windows](#tmux-commands-for-windows)
* [panes](#panes)
  * [shortcuts for panes](#shortcuts-for-panes)
  * [tmux commands for panes](#tmux-commands-for-panes)
* [copy mode](#copy-mode)
  * [shortcuts for copy mode](#shortcuts-for-copy-mode)
  * [tmux commands for copy mode](#tmux-commands-for-copy-mode)
* [misc](#misc)
  * [shortcuts for misc](#shortcuts-for-misc)
  * [tmux commands for misc](#tmux-commands-for-misc)
* [help](#help)
  * [linux commands for help](#linux-commands-for-help)
  * [tmux commands for help](#tmux-commands-for-help)
  * [shortcuts for help](#shortcuts-for-help)
* [tmux format](#tmux-format)

> \[!NOTE|label:references:]
>
> * [tmux cheatsheet](https://tmuxcheatsheet.com/)
> * [awesome tmux](https://github.com/rothgar/awesome-tmux)
> * [MohamedAlaa/tmux-cheatsheet.markdown](https://gist.github.com/MohamedAlaa/2961058)

## files

| FILES                             | DESCRIPTION                      |
| --------------------------------- | -------------------------------- |
| `~/.tmux.conf`                    |                                  |
| `$XDG_CONFIG_HOME/tmux/tmux.conf` |                                  |
| `~/.config/tmux/tmux.conf`        | Default tmux configuration file. |
| `/opt/homebrew/etc/tmux.conf`     | System-wide configuration file.  |

### alias

| COMMAND          | ALIAS               |
| ---------------- | ------------------- |
| `attach-session` | `attach`, `at`, `a` |
| `detach-client`  | `detach`            |
| `has-session`    | `has`               |
| `list-clients`   | `lsc`               |
| `list-commands`  | `lscm`              |
| `list-sessions`  | `ls`                |
| `lock-client`    | `lockc`             |
| `lock-session`   | `locks`             |
| `new-session`    | `new`               |
| `refresh-client` | `refresh`           |
| `rename-session` | `rename`            |
| `show-messages`  | `showmsgs`          |
| `source-file`    | `source`            |
| `start-server`   | `start`             |
| `suspend-client` | `suspend`           |
| `switch-client`  | `switchc`           |

## sessions

### linux commands

| COMMAND                                     | DESCRIPTION                                                          |
| ------------------------------------------- | -------------------------------------------------------------------- |
| `tmux`                                      | start a new session                                                  |
| `tmux new-session`                          | start a new session                                                  |
| `tmux new`                                  | start a new session                                                  |
| `tmux new -s <name>`                        | start a new session with a name                                      |
| `tmux new-session -A -s <name>`             | start a new session or attach to an existing session named mysession |
| `tmux new -s <name> -n <window>`            | start a new session with a name and a window                         |
| `tmux new-session -d -s <name> '<command>'` | start a new session with a name and a command                        |
| `tmux list-sessions`                        | list all sessions                                                    |
| `tmux ls`                                   | list all sessions                                                    |
| `tmux kill-session -t <name>`               | kill/delete a session                                                |
| `tmux kill-ses -t <name>`                   | kill/delete a session                                                |
| `tmux kill-session -a`                      | kill/delete all sessions but the current                             |
| `tmux kill-session -a -t <name>`            | kill/delete all sessions but the                                     |
| `tmux attach-session`                       | attach to the last session                                           |
| `tmux attach`                               | attach to the last session                                           |
| `tmux at`                                   | attach to the last session                                           |
| `tmux a`                                    | attach to the last session                                           |
| `tmux attach-session -t <name>`             | attach to a session                                                  |
| `tmux attach -t <name>`                     | attach to a session                                                  |
| `tmux at -t <name>`                         | attach to a session                                                  |
| `tmux a -t <name>`                          | attach to a session                                                  |

### tmux commands

| COMMAND          | DESCRIPTION                                                            |
| ---------------- | ---------------------------------------------------------------------- |
| `:new`           | start a new session                                                    |
| `:new -s <name>` | start a new session with a name                                        |
| `:kill-session`  | kill a session                                                         |
| `:attach -d`     | detach others on the session (Maximize window by detach other clients) |

### shortcuts

| SHORTCUTS                                   | DESCRIPTION                      |
| ------------------------------------------- | -------------------------------- |
| <kbd>ctrl</kbd> + <kbd>b</kbd> <kbd>$</kbd> | rename the current session.      |
| <kbd>ctrl</kbd> + <kbd>b</kbd> <kbd>d</kbd> | detach from the current session. |
| <kbd>ctrl</kbd> + <kbd>b</kbd> <kbd>s</kbd> | list all sessions.               |
| <kbd>ctrl</kbd> + <kbd>b</kbd> <kbd>w</kbd> | session and window preview       |
| <kbd>ctrl</kbd> + <kbd>b</kbd> <kbd>(</kbd> | move to previous session         |
| <kbd>ctrl</kbd> + <kbd>b</kbd> <kbd>)</kbd> | move to next session             |

## windows

### shortcuts for windows

| SHORTCUTS                                      | DESCRIPTION                     |
| ---------------------------------------------- | ------------------------------- |
| <kbd>ctrl</kbd> + <kbd>b</kbd> <kbd>c</kbd>    | create a new window             |
| <kbd>ctrl</kbd> + <kbd>b</kbd> <kbd>,</kbd>    | rename the current window       |
| <kbd>ctrl</kbd> + <kbd>b</kbd> <kbd>&</kbd>    | close the current window        |
| <kbd>ctrl</kbd> + <kbd>b</kbd> <kbd>w</kbd>    | list windows                    |
| <kbd>ctrl</kbd> + <kbd>b</kbd> <kbd>p</kbd>    | preview window                  |
| <kbd>ctrl</kbd> + <kbd>b</kbd> <kbd>n</kbd>    | next window                     |
| <kbd>ctrl</kbd> + <kbd>b</kbd> <kbd>0..9</kbd> | switch to window 0..9           |
| <kbd>ctrl</kbd> + <kbd>b</kbd> <kbd>l</kbd>    | toggle between last two windows |

### tmux commands for windows

| COMMAND                                         | DESCRIPTION                                        |
| ----------------------------------------------- | -------------------------------------------------- |
| `:swap-window -s <src> -t <dst>`                | swap window with window                            |
| `:swap-window -t -1`                            | swap window with the previous one                  |
| `:move-window -s src_ses:win -t target_ses:win` | move window from src\_ses to target\_ses           |
| `:movew -s foo:0 -t bar:9`                      | move window 0 from session foo to 9 in session bar |
| `:movew -s 0:0 -t 1:9`                          | move window 0 from session 0 to 9 in session 1     |
| `:move-window -s src_session:src_window`        | reposition window in the current session           |
| `:movew -s 0:9`                                 | reposition window 9 to the current session         |
| `:move-window -r`                               | renumber windows to remove gap in the sequence     |
| `:movew -r`                                     | renumber windows to remove gap in the sequence     |

## panes

### shortcuts for panes

| SHORTCUTS                                                     | DESCRIPTION                  |
| ------------------------------------------------------------- | ---------------------------- |
| <kbd>ctrl</kbd> + <kbd>b</kbd> <kbd>;</kbd>                   | toggle last active pane      |
| <kbd>ctrl</kbd> + <kbd>b</kbd> <kbd>%</kbd>                   | split pane vertically        |
| <kbd>ctrl</kbd> + <kbd>b</kbd> <kbd>"</kbd>                   | split pane horizontally      |
| <kbd>ctrl</kbd> + <kbd>b</kbd> <kbd>{</kbd>                   | move pane left               |
| <kbd>ctrl</kbd> + <kbd>b</kbd> <kbd>}</kbd>                   | move pane right              |
| <kbd>ctrl</kbd> + <kbd>b</kbd> <kbd>↑</kbd>                   | move pane up                 |
| <kbd>ctrl</kbd> + <kbd>b</kbd> <kbd>←</kbd>                   | move pane left               |
| <kbd>ctrl</kbd> + <kbd>b</kbd> <kbd>→</kbd>                   | move pane right              |
| <kbd>ctrl</kbd> + <kbd>b</kbd> <kbd>␣</kbd>                   | toggle between pane layouts  |
| <kbd>ctrl</kbd> + <kbd>b</kbd> <kbd>o</kbd>                   | move to the next pane        |
| <kbd>ctrl</kbd> + <kbd>b</kbd> <kbd>q</kbd>                   | show pane numbers            |
| <kbd>ctrl</kbd> + <kbd>b</kbd> <kbd>q</kbd> <kbd>0..9</kbd>   | swith/select the pane number |
| <kbd>ctrl</kbd> + <kbd>b</kbd> <kbd>z</kbd>                   | toggle pane zoom             |
| <kbd>ctrl</kbd> + <kbd>b</kbd> <kbd>!</kbd>                   | convert pannel into a window |
| <kbd>ctrl</kbd> + <kbd>b</kbd> + <kbd>→</kbd>                 | resize current pane width    |
| <kbd>ctrl</kbd> + <kbd>b</kbd> <kbd>ctrl</kbd> + <kbd>→</kbd> | resize current pane width    |
| <kbd>ctrl</kbd> + <kbd>b</kbd> + <kbd>←</kbd>                 | resize current pane width    |
| <kbd>ctrl</kbd> + <kbd>b</kbd> <kbd>ctrl</kbd> + <kbd>←</kbd> | resize current pane width    |
| <kbd>ctrl</kbd> + <kbd>b</kbd> + <kbd>↓</kbd>                 | resize current pane height   |
| <kbd>ctrl</kbd> + <kbd>b</kbd> <kbd>ctrl</kbd> + <kbd>↓</kbd> | resize current pane height   |
| <kbd>ctrl</kbd> + <kbd>b</kbd> + <kbd>↑</kbd>                 | resize current pane height   |
| <kbd>ctrl</kbd> + <kbd>b</kbd> <kbd>ctrl</kbd> + <kbd>↑</kbd> | resize current pane height   |
| <kbd>ctrl</kbd> + <kbd>b</kbd> <kbd>x</kbd>                   | close/kill the current pane  |

### tmux commands for panes

| COMMAND                   | DESCRIPTION                                                                                                                        |
| ------------------------- | ---------------------------------------------------------------------------------------------------------------------------------- |
| `:split-window -h`        | <p>== <kbd>ctrl</kbd> + <kbd>b</kbd> <kbd>%</kbd><br>split the current pane with a vertical line to create a horizontal layout</p> |
| `:split-window -v`        | <p>== <kbd>ctrl</kbd> + <kbd>b</kbd> <kbd>"</kbd><br>split the current pane with a horizontal line to create a vertical layout</p> |
| `:join-pane -s 2 -t 1`    | join two windows as panes (merge window 2 to window 1 as panes)                                                                    |
| `:joinp -s 2.1 -t 1.0`    | move pane from one window to another (move pane 1 from window 2 to pane after 0 of window 1)                                       |
| `:setw synchronize-panes` | toggle synchronize panes (send command to all panes)                                                                               |

## copy mode

### shortcuts for copy mode

| SHORTCUTS                                      | DESCRIPTION                               |
| ---------------------------------------------- | ----------------------------------------- |
| <kbd>ctrl</kbd> + <kbd>b</kbd> <kbd>\[</kbd>   | enter copy mode                           |
| <kbd>ctrl</kbd> + <kbd>b</kbd> <kbd>PgUp</kbd> | enter copy mode and scroll up one page up |
| <kbd>q</kbd>                                   | quit copy mode                            |
| <kbd>g</kbd>                                   | go to the top of the buffer               |
| <kbd>G</kbd>                                   | go to the bottom of the buffer            |
| <kbd>↑</kbd>                                   | scroll up one line                        |
| <kbd>↓</kbd>                                   | scroll down one line                      |
| <kbd>k</kbd>                                   | move cursor up                            |
| <kbd>j</kbd>                                   | move cursor down                          |
| <kbd>h</kbd>                                   | move cursor left                          |
| <kbd>l</kbd>                                   | move cursor right                         |
| <kbd>w</kbd>                                   | move cursor forward one worda at a time   |
| <kbd>b</kbd>                                   | move cursor backward one word at a time   |
| <kbd>/</kbd>                                   | search forward                            |
| <kbd>?</kbd>                                   | search backward                           |
| <kbd>n</kbd>                                   | next keyword occurrence                   |
| <kbd>N</kbd>                                   | previous keyword occurrence               |
| <kbd>␣</kbd>                                   | start selection                           |
| <kbd>esc</kbd>                                 | clear selection                           |
| <kbd>⏎</kbd>                                   | copy selection to clipboard               |
| <kbd>ctrl</kbd> + <kbd>b</kbd> <kbd>]</kbd>    | paste selection                           |

### tmux commands for copy mode

| COMMAND                 | DESCRIPTION                                      |
| ----------------------- | ------------------------------------------------ |
| `:setw -g mode-keys vi` | set vi mode keys for copy mode                   |
| `:show-buffer`          | show the buffer content                          |
| `:capture-pane`         | copy entire visible contents of pane to a buffer |
| `:list-buffers`         | list all buffers                                 |
| `:choose-buffer`        | choose a buffer to paste                         |
| `:save-buffer <file>`   | save buffer to a file                            |
| `:delete-buffer -b 1`   | delete buffer 1                                  |

## misc

### shortcuts for misc

| SHORTCUTS                                   | DESCRIPTION        |
| ------------------------------------------- | ------------------ |
| <kbd>ctrl</kbd> + <kbd>b</kbd> <kbd>:</kbd> | enter command mode |

### tmux commands for misc

| COMMAND           | DESCRIPTION                 |
| ----------------- | --------------------------- |
| `:set -g OPTION`  | set OPTION for all sessions |
| `:setw -g OPTION` | set OPTION for all windows  |
| `:set mouse on`   | enable mouse mode           |

## help

### linux commands for help

| COMMAND                  | DESCRIPTION                                |
| ------------------------ | ------------------------------------------ |
| `$ tmux list-keys`       | list key bindings ( shortcuts )            |
| `$ tmux info`            | show every session, window, panes, etc ... |
| `$ tmux show -g`         | show global options                        |
| `$ tmux show-options -g` | show global options                        |

### tmux commands for help

| COMMAND      | DESCRIPTION                     |
| ------------ | ------------------------------- |
| `:list-keys` | list key bindings ( shortcuts ) |

### shortcuts for help

| SHORTCUTS                                   | DESCRIPTION |
| ------------------------------------------- | ----------- |
| <kbd>ctrl</kbd> + <kbd>b</kbd> <kbd>?</kbd> | show help   |

## [tmux format](https://github.com/greymd/tmux-xpanes/wiki/Tmux-Format)

| VARIABLE NAME            | REPLACED WITH                                          |
| ------------------------ | ------------------------------------------------------ |
| alternate\_on            | If pane is in alternate screen                         |
| alternate\_saved\_x      | Saved cursor X in alternate screen                     |
| alternate\_saved\_y      | Saved cursor Y in alternate screen                     |
| buffer\_sample           | First 50 characters from the specified buffer          |
| buffer\_size             | Size of the specified buffer in bytes                  |
| client\_activity         | Integer time client last had activity                  |
| client\_activity\_string | String time client last had activity                   |
| client\_created          | Integer time client created                            |
| client\_created\_string  | String time client created                             |
| client\_cwd              | Working directory of client                            |
| client\_height           | Height of client                                       |
| client\_last\_session    | Name of the client's last session                      |
| client\_prefix           | 1 if prefix key has been pressed                       |
| client\_readonly         | 1 if client is readonly                                |
| client\_session          | Name of the client's session                           |
| client\_termname         | Terminal name of client                                |
| client\_tty              | Pseudo terminal of client                              |
| client\_utf8             | 1 if client supports utf8                              |
| client\_width            | Width of client                                        |
| cursor\_flag             | Pane cursor flag                                       |
| cursor\_x                | Cursor X position in pane                              |
| cursor\_y                | Cursor Y position in pane                              |
| history\_bytes           | Number of bytes in window history                      |
| history\_limit           | Maximum window history lines                           |
| history\_size            | Size of history in bytes                               |
| host                     | Hostname of local host                                 |
| insert\_flag             | Pane insert flag                                       |
| keypad\_cursor\_flag     | Pane keypad cursor flag                                |
| keypad\_flag             | Pane keypad flag                                       |
| line                     | Line number in the list                                |
| mouse\_any\_flag         | Pane mouse any flag                                    |
| mouse\_button\_flag      | Pane mouse button flag                                 |
| mouse\_standard\_flag    | Pane mouse standard flag                               |
| mouse\_utf8\_flag        | Pane mouse UTF-8 flag                                  |
| pane\_active             | 1 if active pane                                       |
| pane\_current\_command   | Current command if available                           |
| pane\_current\_path      | Current path if available                              |
| pane\_dead               | 1 if pane is dead                                      |
| pane\_height             | Height of pane                                         |
| pane\_id                 | Unique pane ID                                         |
| pane\_in\_mode           | If pane is in a mode                                   |
| pane\_index              | Index of pane                                          |
| pane\_pid                | PID of first process in pane                           |
| pane\_start\_command     | Command pane started with                              |
| pane\_start\_path        | Path pane started with                                 |
| pane\_tabs               | Pane tab positions                                     |
| pane\_title              | Title of pane                                          |
| pane\_tty                | Pseudo terminal of pane                                |
| pane\_width              | Width of pane                                          |
| saved\_cursor\_x         | Saved cursor X in pane                                 |
| saved\_cursor\_y         | Saved cursor Y in pane                                 |
| scroll\_region\_lower    | Bottom of scroll region in pane                        |
| scroll\_region\_upper    | Top of scroll region in pane                           |
| session\_attached        | 1 if session attached                                  |
| session\_created         | Integer time session created                           |
| session\_created\_string | String time session created                            |
| session\_group           | Number of session group                                |
| session\_grouped         | 1 if session in a group                                |
| session\_height          | Height of session                                      |
| session\_id              | Unique session ID                                      |
| session\_name            | Name of session                                        |
| session\_width           | Width of session                                       |
| session\_windows         | Number of windows in session                           |
| window\_active           | 1 if window active                                     |
| window\_find\_matches    | Matched data from the find-window command if available |
| window\_flags            | Window flags                                           |
| window\_height           | Height of window                                       |
| window\_id               | Unique window ID                                       |
| window\_index            | Index of window                                        |
| window\_layout           | Window layout description                              |
| window\_name             | Name of window                                         |
| window\_panes            | Number of panes in window                              |
| window\_width            | Width of window                                        |
| wrap\_flag               | Pane wrap flag                                         |
