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

# Tmux

### install

```bash
// ubuntu & devian
$ sudo apt install tmux

// Centos & Fedora
$ sudo yum install tmux

// Mac OS
$ brew install tmux
```

### copy & paste

```

tmux 단축키 + [ : 스크롤모드
Spacebar : 블럭모드
tmux 단축키 + ] : 붙여넣기
Enter : 복사
```

## 알아둘법한 tmux 단축키

| command     | menual                                                     |
| ----------- | ---------------------------------------------------------- |
| C-b C-b     | Send the prefix key                                        |
| C-b C-o     | Rotate through the panes                                   |
| C-b C-z     | Suspend the current client                                 |
| C-b Space   | Select next layout                                         |
| C-b !       | Break pane to a new window                                 |
| C-b "       | Split window vertically                                    |
| C-b #       | List all paste buffers                                     |
| C-b $       | Rename current session                                     |
| C-b %       | Split window horizontally                                  |
| C-b &       | Kill current window                                        |
| C-b '       | Prompt for window index to select                          |
| C-b (       | Switch to previous client                                  |
| C-b )       | Switch to next client                                      |
| C-b ,       | Rename current window                                      |
| C-b -       | Delete the most recent paste buffer                        |
| C-b .       | Move the current window                                    |
| C-b /       | Describe key binding                                       |
| C-b 0       | Select window 0                                            |
| C-b 1       | Select window 1                                            |
| C-b 2       | Select window 2                                            |
| C-b 3       | Select window 3                                            |
| C-b 4       | Select window 4                                            |
| C-b 5       | Select window 5                                            |
| C-b 6       | Select window 6                                            |
| C-b 7       | Select window 7                                            |
| C-b 8       | Select window 8                                            |
| C-b 9       | Select window 9                                            |
| C-b :       | Prompt for a command                                       |
| C-b ;       | Move to the previously active pane                         |
| C-b =       | Choose a paste buffer from a list                          |
| C-b ?       | List key bindings                                          |
| C-b C       | Customize options                                          |
| C-b D       | Choose and detach a client from a list                     |
| C-b E       | Spread panes out evenly                                    |
| C-b L       | Switch to the last client                                  |
| C-b M       | Clear the marked pane                                      |
| C-b \[      | Enter copy mode                                            |
| C-b ]       | Paste the most recent paste buffer                         |
| C-b c       | Create a new window                                        |
| C-b d       | Detach the current client                                  |
| C-b f       | Search for a pane                                          |
| C-b i       | Display window information                                 |
| C-b l       | Select the previously current window                       |
| C-b m       | Toggle the marked pane                                     |
| C-b n       | Select the next window                                     |
| C-b o       | Select the next pane                                       |
| C-b p       | Select the previous window                                 |
| C-b q       | Display pane numbers                                       |
| C-b r       | Redraw the current client                                  |
| C-b s       | Choose a session from a list                               |
| C-b t       | Show a clock                                               |
| C-b w       | Choose a window from a list                                |
| C-b x       | Kill the active pane                                       |
| C-b z       | Zoom the active pane                                       |
| C-b {       | Swap the active pane with the pane above                   |
| C-b }       | Swap the active pane with the pane below                   |
| C-b \~      | Show messages                                              |
| C-b DC      | Reset so the visible part of the window follows the cursor |
| C-b PPage   | Enter copy mode and scroll up                              |
| C-b Up      | Select the pane above the active pane                      |
| C-b Down    | Select the pane below the active pane                      |
| C-b Left    | Select the pane to the left of the active pane             |
| C-b Right   | Select the pane to the right of the active pane            |
| C-b M-1     | Set the even-horizontal layout                             |
| C-b M-2     | Set the even-vertical layout                               |
| C-b M-3     | Set the main-horizontal layout                             |
| C-b M-4     | Set the main-vertical layout                               |
| C-b M-5     | Select the tiled layout                                    |
| C-b M-n     | Select the next window with an alert                       |
| C-b M-o     | Rotate through the panes in reverse                        |
| C-b M-p     | Select the previous window with an alert                   |
| C-b M-Up    | Resize the pane up by 5                                    |
| C-b M-Down  | Resize the pane down by 5                                  |
| C-b M-Left  | Resize the pane left by 5                                  |
| C-b M-Right | Resize the pane right by 5                                 |
| C-b C-Up    | Resize the pane up                                         |
| C-b C-Down  | Resize the pane down                                       |
| C-b C-Left  | Resize the pane left                                       |
| C-b C-Right | Resize the pane right                                      |
| C-b S-Up    | Move the visible part of the window up                     |
| C-b S-Down  | Move the visible part of the window down                   |
| C-b S-Left  | Move the visible part of the window left                   |
| C-b S-Right | Move the visible part of the window right                  |

## Tmux Plugin install

git clone <https://github.com/tmux-plugins/tpm> \~/.tmux/plugins/tpm

## tmux Script

```bash

Notes for video: http://www.youtube.com/watch?v=OW-lKJDFOzc

add to ~/.tmux.conf

# vim keys in copy or choice mode
set-window-option -g mode-keys vi

# copying selection vim style
# http://jasonwryan.com/blog/2011/06/07/copy-and-paste-in-tmux/
# https://github.com/myfreeweb/dotfiles/blob/master/tmux.conf
bind-key Escape copy-mode   # enter copy mode; default [
bind-key -t vi-copy Escape cancel  # exit copy mode; or hit q
bind-key p paste-buffer    # paste; default ]
bind-key -t vi-copy v begin-selection  # begin visual mode
bind-key -t vi-copy V select-line  # visual line
bind-key -t vi-copy y copy-selection  # yank
bind-key -t vi-copy r rectangle-toggle   # visual block toggle

# read and write and delete paste buffer ( xsel method)
# https://wiki.archlinux.org/index.php/Tmux#ICCCM_Selection_Integration
# ctrl+shift+v
bind-key < command-prompt -p "send to tmux:" "run-shell 'tmux set-buffer -- \"$(xsel -o -b)\"'"
bind-key > command-prompt -p "send to xsel:" "run-shell 'tmux show-buffer | xsel -i -b'"
bind-key + command-prompt "delete-buffer"
```

tmux master link (<https://github.com/gotbletu/shownotes/blob/master/tmux_copy_mode_vim.txt>)

```
## 2번째 
# general
set -g default-terminal "screen-256color"
set -g history-limit 8192


# unbind the prefix and bind it to Ctrl-a like screen.
unbind C-b
set -g prefix C-a
bind a send-prefix
bind C-a send-prefix
bind b send-prefix
bind C-b send-prefix


# act like vim.
set -g mode-keys vi
bind h select-pane -L
bind j select-pane -D
bind k select-pane -U
bind l select-pane -R

bind -T copy-mode-vi "v" send -X begin-selection
bind -T copy-mode-vi "V" send -X rectangle-toggle
bind -T copy-mode-vi "y" send -X copy-selection-and-cancel


# shortcut for moving tmux buffer to clipboard
# useful if you've selected with the mouse
bind-key -nr C-y run "tmux show-buffer | xclip -in -selection clipboard $> /dev/null"

# don't wait for escape sequences
set -sg escape-time 50

# fix titlebar
set -g set-titles on
set -g set-titles-string "#T"

# mouse friendly
set -g mouse on


#### color (Solarized 256)
set -g status-style bg=colour235,fg=colour136
setw -g window-status-style fg=colour244
setw -g window-status-current-style fg=colour166
setw -g window-status-activity-style fg=colour61
setw -g window-status-bell-style fg=colour61
set -g pane-border-style fg=colour235
set -g pane-active-border-style fg=colour240
set -g message-style bg=colour235,fg=colour166
<https://knowledgeforengineers.tistory.com/262>
```
