# tmux

##### Sessions

Start session

- `tmux new`
- `tmux new -s mysession`

Show sessions

- tmux ls

Kill sessions

- `tmux kill-session  -t mysession`
- `tmux kill-session -a` ;kill all sessions but last session

Attach sessions

- `tmux a `
- `tmux a -t #`
- `tmux a -t mysession`

Save &amp; Restore

- [How To Save And Restore Tmux Environments Across Reboots In Linux](https://ostechnix.com/save-and-restore-tmux-environment/)

##### Keyboard

- [Tmux Cheat Sheet](https://tmuxcheatsheet.com/)

PREFIX: CTRL+b

sessions

- Detach from session: PREFIX + d
- Rename session: PREFIX + $
- Move to previous session: PREFIX + (
- Move to next session: PREFIX + )

Windows

- Create a new window: PREFIX + c
- Rename the window: PREFIX + ,
- Move the window: PREFIX + {window-number}
- Close current window: PREFIX + &amp;
- Move to previous window: PREFIX + p
- Move to next window: PREFIX + n
- Go to any window: PREFIX + s

Panes

- Split panes horizontally: PREFIX + "
- Split panes vertically: PREFIX + %
- Switch between panes: PREFIX + Left/Right/Up/Down
- Swap between horizontal and vertical layouts: PREFIX + space
- Toggle pane zoom: PREFIX + z

Copy Mode

- Enter copy mode: PREFIX + \[
- Exit copy mode: q
- Search key word: Ctrl + s
- Move to next search: n
- Move to previous search: N

##### Configuration

`~/.tmux.conf`

Reload the configuration

```bash
tmux source ~/.tmux.conf
```

For Ubuntu/Debian

```
# Enable 256 color in terminal
set -g default-terminal "tmux-256color"

# Fix the dynamic title name
set-option -g allow-rename off

# set vi-mode
set-window-option -g mode-keys vi
# keybindings
bind-key -T copy-mode-vi v send-keys -X begin-selection
bind-key -T copy-mode-vi C-v send-keys -X rectangle-toggle
bind-key -T copy-mode-vi y send-keys -X copy-selection-and-cancel

# Window status
set-window-option -g window-status-current-style 'bg=#282a36 fg=#f8f8f2 bold'
```

For RHEL

```
# Fix the dynamic title name
set-option -g allow-rename off
```

vi-mode

- 行模式：Shift + v
- 列模式：Ctrl + v
- 取消：y
- 複製：Enter
- 貼上：PREFIX + \]

```
# set vi-mode
set-window-option -g mode-keys vi
# keybindings
bind-key -T copy-mode-vi v send-keys -X begin-selection
bind-key -T copy-mode-vi C-v send-keys -X rectangle-toggle
bind-key -T copy-mode-vi y send-keys -X copy-selection-and-cancel
```

##### Plugin

- [Tmux Plugin Manager: A Must-Have For Tmux Power Users](https://ostechnix.com/install-tmux-plugin-manager/)

##### FAQ

> Window 無法固定標題名稱

Solution: `~/.tmux.conf`

```
set-option -g allow-rename off
```

##### Learn

- \[Video\] [Tmux has forever changed the way I write code.](https://www.youtube.com/watch?v=DzNmUNvnB04)
- [ssh 遠端登入後自動開啟或進入 Tmux](https://ostechnix.com/enhancing-ssh-login-with-a-tmux-session-selection-menu/)