til icon indicating copy to clipboard operation
til copied to clipboard

tmux

Open raycon opened this issue 4 years ago • 1 comments

tmux

설치

sudo apt install tmux

용어

  • Session: tmux의 실행 단위
  • Window: 세션을 구성하는 화면 단위
  • Pane: 윈도우를 구성하는 화면 단위
  • Prefix: tmux 명령을 실행하기 위해 입력하는 키, 기본값: Ctrl+B, <C-b> 로 표현.

명령

  • <C-b> 입력 후 명령 키를 누른다.
  • <C-b> 입력 후 : 를 눌러서 명령어 모드로 진입한다.

$가 붙은 명령은 쉘에서 실행하는 명령어를 의미한다.

Session

# 새 세션 생성
$ tmux
$ tmux new
$ tmux new -s <session-name>

# 세션 이름 변경
<C-b> $

# 세션 중단
<C-b> d

# 세션 목록
$ tmux ls

# 최근 세션 재개
$ tmux [ a | at | attach | attach-session ]

# 세션 재개
$ tmux a -t <session-number or session-name>

# 세션 종료
$ exit
$ tmux kill-ses -t <session-name>
$ tmux kill-sesion -t <session-name>

# 세션 이동
<C-b> (
<C-b> )

Window

# 새로운 세션을 시작하면서 윈도우 이름 지정
$ tmux new -n <window-name>

# 윈도우 생성
<C-b> c

# 윈도우 이름 변경
<C-b> ,

# 윈도우 종료
<C-b> &

# 이전, 다음 윈도우 이동
<C-b> n
<C-b> p

# 윈도우 번호로 이동
<C-b> <window-number>

# 윈도우 위치 변경
: swap-window -s 2 -t 1
: swap-window -t 1

Panes

# 세로 분할
<C-b> %

# 가로 분할
<C-b> "

# 좌, 우 이동
<C-b> {
<C-b> }

# 최근 활성화되었던 Pane으로 이동
<C-b> ;

# 방향키로 이동
<C-b> <arrow-key>

# 다음 Pane으로 이동
<C-b> o

# 사이즈 조절
<C-b-arrow-key>
<C-b> <C-arrow-key>

# Window로 변경
<C-b> !

# Pane 종료
<C-b> x

Alias 지정

alias tl='tmux ls'
alias ta='tmux a'
alias tas='tmux a -t'
alias tn='tmux new'
alias tns='tmux new -s'
alias tk='tmux kill-session -t'
alias tka='tmux kill-session -a'

환경 설정

~/.tmux.conf 를 다음과 같이 설정한다.

bind h select-pane -L
bind j select-pane -D
bind k select-pane -U
bind l select-pane -R
bind -n C-d detach

플러그인

Tmux Plugin Manager를 사용해서 쉽게 관리할 수 있다.

installation 항목 참고해서 설치한다.

resurrect

시스템을 재시작 하면 tmux 세션이 없어지는데, resurrect를 사용하면 저장 후 복원 할 수 있다.

~/.tmux.conf 파일에 다음 내용을 추가한다.

set -g @plugin 'tmux-plugins/tmux-resurrect'

<C-b> I 를 눌러서 플러그인을 설치한다. (대문자 i). 설치 완료 후 <C-b> <C-s>를 누르면 저장되고, <C-b> <C-r>을 누르면 복원된다.

nvim 세션도 저장되도록 하려면 ~/.config/nvim/init.vim'tpope/vim-obsession 플러그인을 설치하고 ~/.tmux.conf에 다음 내용을 추가한다.

set -g @resurrect-strategy-nvim 'session'    # Save & Restore nvim session

continuum

resurrect를 사용해서 자동으로 저장하는 기능을 구현한 플러그인

set -g @plugin 'tmux-plugins/tmux-continuum' # Continuous saving
set -g @continuum-restore 'on'

raycon avatar Jan 06 '21 02:01 raycon

  • https://github.com/tmux-plugins/tpm

raycon avatar Jan 06 '21 05:01 raycon