命令

指令 bash tmux
新建 tmux new -s session-name :new -s session-name
新窗口 c
切換窗口 p[or n or number]
滾屏 [
連接 tmux attach [-t session-name]
斷開 exit d
停止 tmux kill-session -t session-name
重命名 tmux rename-session -t old-name new-name ,
列出 tmux ls s
垂直分割 %
水平分割
pane最大 z
pane resize C-Arrow
退出pane exit

插件

tpm 簡介

tmux 支持插件. Tmux Plugin Manager 是一個贊率很高的插件管理器.
安裝 tpm 如下:

  1. $ git clone https://github.com/tmux-plugins/tpm ~/.tmux/plugins/tpm
  2. # 在 ~/.tmux.conf (或 ~/.config/tmux/tmux.conf) 末尾添加:
  3. # List of plugins
  4. set -g @plugin 'tmux-plugins/tpm'
  5. set -g @plugin 'tmux-plugins/tmux-sensible'
  6. # Initialize TMUX plugin manager (keep this line at the very bottom of tmux.conf)
  7. run '~/.tmux/plugins/tpm/tpm'
  8. # 重啓 tmux 即可 (可以 tmux source ~/.tmux.conf 手動加載)

如何安裝插件

只需在 ~/.tmux.conf 中添加

  1. set -g @plugin '...'

然後按快捷鍵 prefix + I, 插件會被克隆到 ~/.tmux/plugins 中.

安裝完成後會提示:

  1. TMUX environment reloaded.
  2. 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.conf 中添加:

  1. set -g @plugin 'tmux-plugins/tmux-resurrect'
  2. set -g @plugin 'tmux-plugins/tmux-continuum'
  3. # Last saved environment is automatically restored when tmux is started.
  4. set -g @continuum-restore 'on'

prefix + I 安裝插件.

使用

手動保存:

  1. prefix-Ctrl-s

手動恢復:

  1. prefix-Ctrl-r

說明

1. 滾屏

在 tmux 中,要先 <prefix>[ 才可以使用 vi 的操作方式滾屏。

~/.tmux.conf

  1. set -g prefix ^g # 前綴設置爲 <C-g>
  2. unbind ^b # 解綁 <C-b>
  3. set-option -g status-utf8 on # 開啓狀態欄UTF-8支持
  4. # cp mode
  5. set-window-option -g mode-keys vi # 複製模式中的默認鍵盤佈局使用vi
  6. bind h select-pane -L # h -- left
  7. bind l select-pane -R # l -- right
  8. bind k select-pane -U # k -- up
  9. bind j select-pane -D # j -- down

FAQ

1. vim 颜色不对

根据: How to use true colors in vim under tmux 设置如下:

在 tmux.conf 中添加

  1. # !!!importent!!! 开启24 bit color 其他方式都无效
  2. set -g default-terminal "tmux-256color"
  3. set -ga terminal-overrides ",*256col*:Tc"

在 .vimrc 中添加(经尝试,这一步可略):

  1. " Enable true color 启用终端24位色
  2. if exists('+termguicolors')
  3. let &t_8f = "\<Esc>[38;2;%lu;%lu;%lum"
  4. let &t_8b = "\<Esc>[48;2;%lu;%lu;%lum"
  5. set termguicolors
  6. endif

鏈接