Docs of Jace-Lab

tmux

tmux is a terminal multiplexer that allows you to split a terminal window into multiple panes and manage multiple terminal sessions.

1. 시작하기 전에: 접두사(Prefix)

tmux의 모든 명령은 Prefix 키를 먼저 누르는 것으로 시작합니다.

  • 기본 Prefix: Ctrl + b

팁: Ctrl + b를 누른 뒤 손을 떼고, 그다음에 원하는 단축키를 입력하면 됩니다.


2. 세션(Session) 관리

세션은 작업 전체의 묶음입니다. 서버에서 로그아웃해도 세션은 살아있습니다.

기능명령어 / 단축키
새 세션 시작tmux new -s [세션이름]
세션 리스트 확인tmux ls
세션 접속 (Attach)tmux attach -t [세션이름]
세션 나가기 (Detach)Prefix + d
세션 종료(터미널에서) exit 입력

세션 목록 확인

  • 세션 목록 보기: Prefix + s

접속 중인 세션의 이름 변경

  • 단축키: Prefix (Ctrl + b) 누른 후 + $ (달러 기호)
  • 방법: 하단 상태 바에 이름 수정 칸이 생기면, 기존 이름을 지우고 새 이름을 입력한 뒤 Enter를 누르세요.

터미널에서 세션 이름 변경

  • 세션 내부에서:
    tmux rename-session [새이름]
  • 세션 외부에서 (특정 세션을 지정):
    tmux rename-session -t [기존이름] [새이름]

세션 안에서 바로 만들기 (강제 명령)

현재 세션을 유지한 채로 백그라운드에 새 세션을 미리 만들어두고 싶을 때 사용합니다.

  • 명령어:

    tmux new-session -d -s [새세션이름]
    • -d 옵션은 "만들기만 하고 바로 접속(Attach)하지 마라"는 뜻입니다. 이렇게 하면 중첩 오류를 피할 수 있습니다.

세션 안에서 새 세션으로 바로 '이동'하기

현재 세션에서 작업하다가, 즉시 다른 이름의 새 세션을 파서 그리로 넘어가고 싶을 때 유용합니다.

  • 명령어:

    TMUX= tmux new-session -s [새세션이름]
    • TMUX=를 앞에 붙여서 일시적으로 환경 변수를 비워주면, tmux는 현재 세션 안에 있다는 사실을 '망각'하고 새 세션을 정상적으로 실행합니다.

3. 윈도우(Window) 관리

하나의 세션 안에서 여러 개의 탭(Tab)처럼 사용합니다.

  • 새 윈도우 생성: Prefix + c
  • 다음 윈도우로 이동: Prefix + n
  • 이전 윈도우로 이동: Prefix + p
  • 번호로 이동: Prefix + 0 ~ 9
  • 윈도우 이름 변경: Prefix + ,

4. 패인(Pane) 관리: 화면 분할

하나의 화면을 여러 구역으로 나누는 기능입니다. tmux의 꽃이죠!

  • 가로 분할: Prefix + " (따옴표)
  • 세로 분할: Prefix + % (퍼센트)
  • 패인 간 이동: Prefix + 방향키
  • 패인 닫기: Prefix + x (또는 exit 입력)
  • 패인 전체화면 전환: Prefix + z (다시 누르면 복귀)

5. 유용한 꿀팁

  • 스크롤 모드: Prefix + [ 를 누르면 마우스 휠이나 방향키로 이전 기록을 볼 수 있습니다. (나갈 때는 q)
  • 단축키 도움말: Prefix + ? 를 누르면 모든 단축키 목록이 뜹니다.

💡 설정 커스텀 (옵션)

매번 Ctrl + b를 누르는 게 불편하다면, 홈 디렉토리에 .tmux.conf 파일을 만들어 설정을 바꿀 수 있습니다.

# 예시: 마우스 사용 가능하게 설정
set -g mouse on

# 예시: 가로/세로 분할 단축키를 더 직관적인 - 와 | 로 변경
bind | split-window -h
bind - split-window -v

6. tmux.conf

1. 추천 설정 파일 (~/.tmux.conf)

# ==========================================
# 1. 일반 설정
# ==========================================

# 마우스 사용 활성화 (클릭으로 패인 이동, 스크롤 가능)
set -g mouse on

# 히스토리 용량 늘리기 (기본은 너무 적음)
set -g history-limit 10000

# 인덱스 번호를 1부터 시작 (키보드 0번은 멀기 때문)
set -g base-index 1
setw -g pane-base-index 1

# 터미널 색상 보정 (256color 지원)
set -g default-terminal "screen-256color"


# ==========================================
# 2. 단축키 변경 (더 직관적으로)
# ==========================================

# 화면 분할 단축키 변경 (현재 경로 유지하며 분할)
bind | split-window -h -c "#{pane_current_path}"
bind - split-window -v -c "#{pane_current_path}"

# 패인 이동을 Vim 스타일로 (Alt + hjkl)
# Prefix 없이 바로 이동 가능해서 매우 편리함
bind -n M-h select-pane -L
bind -n M-l select-pane -R
bind -n M-k select-pane -U
bind -n M-j select-pane -D

# 설정 파일 리로드 단축키 (Prefix + r)
bind r source-file ~/.tmux.conf \; display "Reloaded!"


# ==========================================
# 3. 디자인 (상태 바)
# ==========================================

# 상태 바 배경색 및 글자색
set -g status-bg black
set -g status-fg white

# 왼쪽: 세션 이름 표시
set -g status-left '#[fg=green][#S] '

# 오른쪽: 날짜 및 시간 표시
set -g status-right '#[fg=cyan]%Y-%m-%d %H:%M'

2. 설정 적용하는 법

파일을 저장한 후, 터미널에서 다음 명령어를 입력해야 바로 적용됩니다.

tmux source-file ~/.tmux.conf

(위 설정을 넣었다면 이후부터는 Prefix + r만 눌러도 적용됩니다.)

3. 이 설정의 핵심 포인트

  • Vim 스타일 이동 (Alt + h/j/k/l): 원래는 Prefix를 누르고 방향키를 눌러야 하지만, 이 설정을 쓰면 Alt 키와 h,j,k,l만으로 화면 사이를 슉슉 날아다닐 수 있습니다.
  • 현재 경로 유지: 새 패인을 나눌 때 이전에 작업하던 폴더 경로에서 바로 시작하게 해줍니다. (이게 안 되면 매번 cd로 이동해야 해서 번거롭거든요.)
  • 마우스 활성화: "터미널은 키보드지!" 하다가도 가끔 마우스 휠로 스크롤하고 싶을 때 정말 유용합니다.

7. 추가 설정정

가장 강력한 TPM(Tmux Plugin Manager) 기반의 설정과 Vim과의 완벽한 통합 설정을 소개해 드릴게요.


1. TPM (Tmux Plugin Manager) 설치

먼저 플러그인을 관리해주는 매니저를 설치해야 합니다.

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

2. 고난도 .tmux.conf 추천 구성

이 설정은 세션 자동 저장/복구, Vim 스타일의 부드러운 이동, 그리고 강력한 테마를 포함합니다.

# ==========================================
# 1. 플러그인 리스트 (TPM)
# ==========================================
set -g @plugin 'tmux-plugins/tpm'
set -g @plugin 'tmux-plugins/tmux-sensible'
set -g @plugin 'tmux-plugins/tmux-resurrect' # 세션 저장/복구
set -g @plugin 'tmux-plugins/tmux-continuum' # 자동 저장
set -g @plugin 'christoomey/vim-tmux-navigator' # Vim-Tmux 완벽 통합
set -g @plugin 'dracula/tmux' # 세련된 테마 (Dracula)

# ==========================================
# 2. 고급 기능 설정
# ==========================================

# 24-bit color 지원 (True Color)
set -as terminal-features ",xterm-256color:RGB"

# 세션 자동 복구 활성화
set -g @continuum-restore 'on'

# Dracula 테마 커스텀 (필요한 정보만 표시)
set -g @dracula-show-powerline true
set -g @dracula-plugins "cpu-usage ram-usage network-bandwidth"
set -g @dracula-show-left-icon session

# ==========================================
# 3. Vim 모드 및 복사 설정
# ==========================================

# 스크롤/복사 모드에서 Vim 단축키 사용
setw -g mode-keys vi
bind-key -T copy-mode-vi 'v' send -X begin-selection     # v로 선택 시작
bind-key -T copy-mode-vi 'y' send -X copy-selection-and-cancel # y로 복사

# ==========================================
# TPM 초기화 (파일의 가장 마지막에 넣으세요)
# ==========================================
run '~/.tmux.conf/plugins/tpm/tpm'

3. 설정 적용 및 플러그인 설치

  1. 파일을 저장한 후 tmux source-file ~/.tmux.conf를 입력합니다.
  2. tmux 안에서 Prefix + I (대문자 i)를 누르면 플러그인들이 자동으로 설치됩니다.

4. 고난도 설정의 핵심 기능

① 세션의 불사신화 (tmux-resurrect & continuum)

  • 컴퓨터를 재부팅해도 열어두었던 패인 구조, 실행 중인 프로그램, 작업 경로가 그대로 복구됩니다.
  • 저장: Prefix + Ctrl-s
  • 복구: Prefix + Ctrl-r (보통 자동 복구 설정 덕분에 알아서 켜집니다.)

② Vim-Tmux Navigator

  • Vim(또는 Neovim) 사용자라면 필수입니다.
  • Vim 창과 tmux 패인 사이를 구별 없이 Ctrl + h, j, k, l만으로 자유롭게 이동할 수 있게 해줍니다. (Vim 쪽에도 관련 플러그인을 깔아야 완벽해집니다.)

③ 복사 모드 (Vi-mode)

  • Prefix + [ 를 눌러 진입했을 때, 방향키가 아닌 h, j, k, l로 이동하고 v로 블록 지정, y로 복사할 수 있습니다. 마우스에 손을 댈 필요가 없어집니다.

8. Prefix 변경

손가락의 피로도를 줄여주는 Prefix 변경과 함께, 손맛을 극대화할 수 있는 추가 고난도 설정들을 정리해 드릴게요. 이 설정까지 마치면 터미널 작업 속도가 비약적으로 상승합니다.


1. Prefix를 Ctrl + a로 변경

대부분의 리눅스/개발 고수들이 사용하는 설정입니다. b는 오른손까지 써야 하지만, a는 왼손 소지(Pinky) 하나로 모든 명령을 시작할 수 있게 해줍니다.

# 기본 Prefix 해제
unbind C-b

# 새로운 Prefix 설정
set -g prefix C-a
bind C-a send-prefix

2. 패인(Pane) 크기 조절 단축키 (Vim 스타일)

화면 비율을 맞출 때 마우스를 쓰지 않고, 방향키나 단축키로 정교하게 조절하는 설정입니다.

# Prefix + H, J, K, L로 패인 크기 조절 (5칸씩)
bind -r H resize-pane -L 5
bind -r J resize-pane -D 5
bind -r K resize-pane -U 5
bind -r L resize-pane -R 5

-r 옵션: Prefix를 한 번만 누르고, 연속해서 HL을 눌러 크기를 계속 조절할 수 있게 해줍니다.


3. 시스템 클립보드와 연동 (Linux/Mac 공용)

tmux 내부에서 복사(y)한 내용을 터미널 밖 메모장이나 브라우저에 붙여넣고 싶을 때 필수입니다.

# xclip 또는 xsel이 설치되어 있어야 함 (Linux 기준)
# 복사 모드에서 'y'를 누르면 시스템 클립보드로 전송
bind-key -T copy-mode-vi 'y' send -X copy-pipe-and-cancel "xclip -selection clipboard -i"

4. 최종 진화형 .tmux.conf 예시

위의 모든 내용을 통합한 완성형 설정입니다.

# --- [1] Prefix 변경 ---
unbind C-b
set -g prefix C-a
bind C-a send-prefix

# --- [2] 인터페이스 및 디자인 ---
set -g mouse on
set -g base-index 1
setw -g pane-base-index 1
set -g renumber-windows on # 윈도우 삭제 시 번호 자동 정렬

# --- [3] 단축키 커스텀 ---
# 현재 경로로 분할
bind | split-window -h -c "#{pane_current_path}"
bind - split-window -v -c "#{pane_current_path}"

# 설정 리로드
bind r source-file ~/.tmux.conf \; display "Config Reloaded!"

# 패인 이동 (Vim 스타일)
bind h select-pane -L
bind j select-pane -D
bind k select-pane -U
bind l select-pane -R

# --- [4] 복사 모드 (Vi-mode) ---
setw -g mode-keys vi
bind-key -T copy-mode-vi v send-step -X begin-selection
bind-key -T copy-mode-vi y send-step -X copy-selection-and-cancel

# --- [5] TPM 플러그인 관리 ---
set -g @plugin 'tmux-plugins/tpm'
set -g @plugin 'tmux-plugins/tmux-resurrect'
set -g @plugin 'tmux-plugins/tmux-continuum'
set -g @plugin 'christoomey/vim-tmux-navigator'

run '~/.tmux/plugins/tpm/tpm'

🚀 적용 가이드

  1. ~/.tmux.conf 파일에 위 내용을 넣고 저장합니다.
  2. 터미널에서 tmux source-file ~/.tmux.conf 실행.
  3. tmux 안에서 Ctrl + a 누른 후 I(대문자)를 눌러 플러그인 설치.

이제 **Ctrl + a**가 여러분의 마법 지팡이가 되었습니다!


.tmux.conf @260811

# ==========================================
# 1. 일반 설정
# ==========================================

# Rebind Prefix to CTRL-A
# set-option -g prefix C-a
# unbind C-b
# bind C-a send-prefix

# General
set -g set-clipboard on         # Use system clipboard
set -g detach-on-destroy off    # Don't exit from tmux when closing a session
set -g escape-time 0            # Remove delay for exiting insert mode with ESC in Neovim
set -g history-limit 1000000    # 히스토리 용량 늘리기 (기본 2,000)
set -g mouse on                 # 마우스 사용 활성화 (클릭으로 패인 이동, 스크롤 가능)
#set -g mouse-utf8 off           # 마우스 확장 프로토콜(SGR) 활성화)
set -g status-interval 3        # Update the status bar every 3 seconds (default: 15 seconds)
set -g allow-passthrough on     # Allow programs in the pane to bypass tmux (e.g. for image preview)
set -g status-position bottom


# 인덱스 번호를 1부터 시작 (키보드 0번은 멀기 때문)
set -g base-index 1
set -g pane-base-index 1
set -g renumber-windows on # Automatically renumber windows when one is closed

# 터미널 색상 보정 256-color and true-color (24-bit)
set -g default-terminal "screen-256color" # Set terminal type for 256-color support
set -ga terminal-overrides ",*256col*:Tc" # Override to enable true-color for compatible terminals

# ==========================================
# 2. 단축키 변경 (더 직관적으로)
# ==========================================

# 화면 분할 단축키 변경 (현재 경로 유지하며 분할)
bind | split-window -h -c "#{pane_current_path}"
bind - split-window -v -c "#{pane_current_path}"

# 패인 이동을 Vim 스타일로 (Alt + hjkl)
# Prefix 없이 바로 이동 가능해서 매우 편리함
bind -n M-h select-pane -L
bind -n M-l select-pane -R
bind -n M-k select-pane -U
bind -n M-j select-pane -D

# 설정 파일 리로드 단축키 (Prefix + r)
unbind r
bind r source-file ~/.tmux.conf \; display "Reloaded!"


# ==========================================
# 3. 디자인 (상태 바)
# ==========================================

# 상태 바 배경색 및 글자색
# set -g status-bg white
# set -g status-fg black

# 왼쪽: 세션 이름 표시
# set -g status-left '#[fg=green][#S] '

# 오른쪽: 날짜 및 시간 표시
#set -g status-right '#[fg=cyan]%Y-%m-%d %H:%M'

# ==========================================
# gruvbox material colorscheme (mostly)
RED="#ea6962"
GREEN="#a9b665"
YELLOW="#d8a657"
BLUE="#7daea3"
MAGENTA="#d3869b"
CYAN="#89b482"
BLACK="#1d2021"
DARK_GRAY="#32302F"
LIGHT_GRAY="#4F4946"
BG="#32302F"
FG="#d4be98"

# Nerdfont characters
HALF_ROUND_OPEN="#(printf '\uE0B6')"
HALF_ROUND_CLOSE="#(printf '\uE0B4')"
TRIANGLE_OPEN="#(printf '\uE0B2')"
TRIANGLE_CLOSE="#(printf '\uE0B0')"

# Uncomment to move statusbar to the top
# set-option -g status-position top

# Basic colors of the Statusbar
set-option -g status-style bg=${BG},fg=${FG}

# Show the window list centered between the left and the right section
set-option -g status-justify centre

# Style and set contents on the left section
set-option -g status-left "\
#[fg=${LIGHT_GRAY},bg=default]${HALF_ROUND_OPEN}\
#[bg=${LIGHT_GRAY},fg=${YELLOW}]#S \
#[fg=${LIGHT_GRAY},bg=default]${TRIANGLE_CLOSE}\
"

# Style and set contents on the right section
set-option -g status-right "\
#[fg=${LIGHT_GRAY},bg=default]${TRIANGLE_OPEN}\
#[bg=${LIGHT_GRAY},fg=${CYAN}] #h\
#[fg=${LIGHT_GRAY},bg=default]${HALF_ROUND_CLOSE}\
"

# Set max length of left and right section
set-option -g status-left-length 100
set-option -g status-right-length 100

# Style and set content for the inactive windows
set-option -g window-status-format "\
 \
#I\
#[fg=${MAGENTA}]:\
#[fg=default]#W\
 \
"

# Style and set content for the active windows
set-option -g window-status-current-format "\
#[fg=${LIGHT_GRAY},bg=default]${HALF_ROUND_OPEN}\
#[bg=${LIGHT_GRAY},fg=default]#I\
#[fg=${RED}]:\
#[fg=default]#W<U+F07C> #{b:pane_current_path}\
#[fg=${LIGHT_GRAY},bg=default]${HALF_ROUND_CLOSE}\
"
#set -g window-status-current-format "#[fg=${cyan_soft},bold] <U+F444> #[underscore]#I:#W#[nounderscore]#{?window_zoomed_flag, <U+F034B> ,}"

# Remove the separator between window list items, as we already have spacing
# "around" inactive items
set-option -g window-status-separator ""

# ==========================================
# 4. 페인 테두리
# ==========================================

# 활성 페인 테두리 색상을 녹색으로 설정
set -g pane-active-border-style fg=green,bg=default

# 비활성 페인 테두리 색상을 흰색(또는 회색)으로 설정
set -g pane-border-style fg=white,bg=default

# 페인 테두리에 상태 표시줄 활성화 (top 또는 bottom)
set -g pane-border-status top

# 활성 페인에는 테두리에 "### ACTIVE ###"라고 크게 표시
set -g pane-border-format "#{?pane_active,#[reverse]  ACTIVE  #[default],  #P: #W  }"

# 활성 페인 테두리를 이중선(double)으로 변경
set -g pane-border-lines double

# 테두리 색상을 눈이 아플 정도의 형광색으로 설정
set -g pane-active-border-style "fg=brightyellow,bg=default"

# ===========
# 5. 복사붙여넣기
# ===========
# 복사 모드에서 vi 스타일 단축키 사용
setw -g mode-keys vi

# v로 블록 선택 시작, y로 복사
bind -T copy-mode-vi v send -X begin-selection
bind -T copy-mode-vi y send -X copy-selection-and-cancel

# Ctrl + b ➡️ [ (복사 모드 진입)
# 복사할 시작 지점에서 v 누르기 (블록 지정 시작)
# 이동키(h, j, k, l 또는 방향키)로 영역 선택
# y 누르기 (복사 완료 및 모드 종료)

On this page