# tmux

* If you ever get a weird error about netsted sessions, just unset the env var TMUX with

```
TMUX=
```

## tmux Create New Session

```
tmux new-session -s <session name>
--OR--
tmux new -s <session name>
```

### tmux List existing session

```
tmux list-sessions
```

### tmux Attatch Existing session

```
tmux attatch-session -t <session-id/session-name>
```

### tmux Kill Existing session

```
tmux kill-session -t <session-id/session-name>
```

### Delete all sessions except current

```
tmux kill-session -a 
```

## Reverse History Search

* Press `Ctrl+R` and type what you are searching for, then hit enter when the command appears

## Pre-Fix Key

* By default it is `Ctrl+B`

## Create a New Window

```
Ctrl+b c
```

## Switch between windows

```
Ctrl+b [0-9]
--OR-- 
Ctrl+b right/left arrow keys 
```

* or to go one previous

```
Ctrl+b p
```

* to go to next

```
Ctrl+b n
```

### Detach Session

```
Ctrl+b d
```

### Rename Window

```
Ctrl+b ,
```

### Move current pane left/right

```
Ctrl+b { #move left 
Ctrl+b } #move right 
```

### Exit pane

```
Ctrl+b x
```

### Resizing Panes

```
#resize height 
Ctrl+b uparrow
Ctrl+b downarrow 
#resize width 
Ctrl+b leftarrow 
Ctrl+b rightarrow 
```

### Convert pane to window

```
Ctrl+b ! 
```

## Nested tmux Sessions

* SSH into remote host
* Can run `tmux ls` and view the tmux sessions
* Example:

```
MINER: 1 windows (created Mon Novv 27 21:33:24 2022) [186x47]
```

* To attatch to that session

```
tmux attatch -t MINER
```

* Use prefix key + d to detatch from the connected session

## Split Terminals Vertical

* `Ctrl+B %`

## Split Terminals Horizontal

* `Ctrl+B "`

## Custom tmux config

* File located `~/.tmux`

```
set -g prefix C-a
bind C-a send-prefix
unbind C-b

#Quality of life stuff 
set -g history-limit 10000
set -g allow-rename off

#Join Windows
bind-key j commpand-prompt -p "join pane from:" "join-pane -s '%%'" 
bind-key -s command-prompt -p "send pane to:" "join-pane -t '%%'"

#search mode VI (default is emacs)
set-windows-option -g mode-keys vi

run-shell /opt/tmux-logging/logging.tmux
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://book.ice-wzl.xyz/tool-guides/tmux-mastery.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
