Skip to main content

tmux 使用

· 2 min read

安装

Ubuntu/Debian

sudo apt install tmux
tmux -V

核心概念

tmux server
└── session: dev
├── window 0: editor
│ └── pane 0
├── window 1: server
│ ├── pane 0
│ └── pane 1
└── window 2: logs
└── pane 0
名词含义
servertmux 后台进程,管理所有会话
client你当前连上的终端界面
session一组窗口的集合,可 detachattach
window一个全屏工作区,类似终端标签页
panewindow 里切出来的小终端

server 和 client 是不同进程,通过 socket 通信。默认 socket 在 /tmp 下的 tmux 用户目录里,也可以用 -L-S 指定不同 socket。

常用命令

  • 使用手册: man tmux
  • 确认默认键位: tmux list-keys -T prefix
  • 新建一个会话: tmux new -s dev

默认配置

~/.tmux.conf
##### prefix #####
# unbind C-b
# set -g prefix C-a
# bind C-a send-prefix

##### basic behavior #####
set -g mouse on
set -g history-limit 50000
set -g escape-time 10
set -g base-index 1
setw -g pane-base-index 1
set -g renumber-windows on

##### copy mode #####
setw -g mode-keys vi

##### split panes in current path #####
bind | split-window -h -c "#{pane_current_path}"
bind - split-window -v -c "#{pane_current_path}"
bind c new-window -c "#{pane_current_path}"

##### pane navigation #####
bind h select-pane -L
bind j select-pane -D
bind k select-pane -U
bind l select-pane -R

##### reload config #####
bind R source-file ~/.tmux.conf \; display-message "tmux.conf reloaded"

##### status line #####
set -g status-interval 5
set -g status-left "#[bold]#S "
set -g status-right "#H %Y-%m-%d %H:%M"

set -g default-terminal "tmux-256color"
set -ga terminal-overrides ",*256col*:Tc"