张芷铭的个人博客

tmux 终端复用器:单窗口多会话,断开后保持运行,支持窗口/窗格分割。

安装与启动

1
2
3
4
5
6
7
# 安装
sudo apt install tmux  # Debian/Ubuntu
sudo dnf install tmux  # RHEL/Fedora

# 启动
tmux                  # 新会话
tmux new -s my_session  # 命名会话

会话管理

操作命令
分离Ctrl-b d
列出tmux ls
重连tmux attach -t 名称
删除tmux kill-session -t 名称
全部删除tmux kill-server

窗口操作

操作快捷键
新建Ctrl-b c
下/上窗口Ctrl-b n / p
列表Ctrl-b w
重命名Ctrl-b ,

窗格操作

操作快捷键
垂直分割Ctrl-b %
水平分割Ctrl-b "
切换Ctrl-b 方向键
关闭exitCtrl-d

配置

1
2
3
4
# ~/.tmux.conf
set -g prefix C-a    # 前缀改为 Ctrl-a
set -g mouse on      # 启用鼠标
bind r source-file ~/.tmux.conf \; display "Reloaded!"

会话持久化

1
2
3
4
5
6
7
8
# 安装 TPM
git clone https://github.com/tmux-plugins/tpm ~/.tmux/plugins/tpm

# ~/.tmux.conf
set -g @plugin 'tmux-plugins/tmux-resurrect'
run '~/.tmux/plugins/tpm/tpm'

# prefix + I 安装,prefix + Ctrl-s 保存,prefix + Ctrl-r 恢复

Comments