命令
| 指令 | bash | tmux |
|---|---|---|
| 新建 | tmux new -s session-name |
|
| 新窗口 | ||
| 切換窗口 | ||
| 滾屏 | ||
| 連接 | tmux attach [-t session-name] |
|
| 斷開 | exit |
|
| 停止 | tmux kill-session -t session-name |
|
| 重命名 | tmux rename-session -t old-name new-name |
|
| 列出 | tmux ls |
|
| 垂直分割 | ||
| 水平分割 | ||
| pane最大 | ||
| pane resize | ||
| 退出pane | exit |
插件
tpm 簡介
tmux 支持插件. Tmux Plugin Manager 是一個贊率很高的插件管理器.
安裝 tpm 如下:
$ git clone https://github.com/tmux-plugins/tpm ~/.tmux/plugins/tpm# 在 ~/.tmux.conf (或 ~/.config/tmux/tmux.conf) 末尾添加:# List of pluginsset -g @plugin 'tmux-plugins/tpm'set -g @plugin 'tmux-plugins/tmux-sensible'# Initialize TMUX plugin manager (keep this line at the very bottom of tmux.conf)run '~/.tmux/plugins/tpm/tpm'# 重啓 tmux 即可 (可以 tmux source ~/.tmux.conf 手動加載)
如何安裝插件
只需在 ~/.tmux.conf 中添加
set -g @plugin '...'
然後按快捷鍵 prefix + I, 插件會被克隆到 ~/.tmux/plugins 中.
安裝完成後會提示:
TMUX environment reloaded.Done, press ENTER to continue.
卸載
只需在 ~/.tmux.conf 中從插件列表中刪除, 再 prefix+alt+U 即可卸載.
快捷鍵
| 快捷鍵 | 作用 |
|---|---|
| prefix + I | Install new plugins from github and refresh TMUX environment |
| prefix + U | updates plugins(s) |
| prefix + alt + U | remove/uninstall plugins not on the plugin list |
恢復會話
假如有諸多 tmux-sessions 需要建立, 則重啓電腦將會負擔重重.
根據 restoring tmux sessions, 可以用兩個插件解決這個問題:
- tmux-resurrect
- 手動保存會話
- tmux-continuum
- 每 15 分鐘自動保存會話
安裝
在 ~/.tmux.conf 中添加:
set -g @plugin 'tmux-plugins/tmux-resurrect'set -g @plugin 'tmux-plugins/tmux-continuum'# Last saved environment is automatically restored when tmux is started.set -g @continuum-restore 'on'
按 prefix + I 安裝插件.
使用
手動保存:
prefix-Ctrl-s
手動恢復:
prefix-Ctrl-r
說明
1. 滾屏
在 tmux 中,要先
<prefix>[才可以使用 vi 的操作方式滾屏。
~/.tmux.conf
set -g prefix ^g # 前綴設置爲 <C-g>unbind ^b # 解綁 <C-b>set-option -g status-utf8 on # 開啓狀態欄UTF-8支持# cp modeset-window-option -g mode-keys vi # 複製模式中的默認鍵盤佈局使用vibind h select-pane -L # h -- leftbind l select-pane -R # l -- rightbind k select-pane -U # k -- upbind j select-pane -D # j -- down
FAQ
1. vim 颜色不对
根据: How to use true colors in vim under tmux 设置如下:
在 tmux.conf 中添加
# !!!importent!!! 开启24 bit color 其他方式都无效set -g default-terminal "tmux-256color"set -ga terminal-overrides ",*256col*:Tc"
在 .vimrc 中添加(经尝试,这一步可略):
" Enable true color 启用终端24位色if exists('+termguicolors')let &t_8f = "\<Esc>[38;2;%lu;%lu;%lum"let &t_8b = "\<Esc>[48;2;%lu;%lu;%lum"set termguicolorsendif
