tmux.conf 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. # vim: set fdm=marker foldenable:
  2. ########## 基本设置 ---{{{
  3. #
  4. # 把 prefix 设置成与 screen 相同,实际上也更好摁一些
  5. set -g prefix C-a
  6. unbind-key C-b
  7. bind-key a send-prefix
  8. set -g buffer-limit 20000;
  9. # 快捷键采用 vi 模式
  10. setw -g mode-keys vi
  11. # 设置默认 Shell 为 bash,但各平台路径各异,需要分别特殊处理
  12. if-shell 'test -x /data/data/com.termux/files/usr/bin/bash' {
  13. set -g default-shell /data/data/com.termux/files/usr/bin/bash
  14. bind-key -n Home send Escape "OH"
  15. bind-key -n End send Escape "OF"
  16. } {
  17. if-shell 'test -x /usr/local/bin/bash' {
  18. set -g default-shell /usr/local/bin/bash
  19. } {
  20. if-shell 'test -x /usr/bin/bash' {
  21. set -g default-shell /usr/bin/bash
  22. } {
  23. run 'tmux set-option -g default-shell "$(command -v bash)"'
  24. }
  25. }
  26. }
  27. # }}}
  28. ########## 终端属性设置 ---{{{
  29. # 全面开启鼠标支持,鼠标可以用来选择窗口及面板,调整面板尺寸,以及复制文本
  30. set -g mouse on
  31. # Use xterm function key sequence
  32. setw -g xterm-keys on
  33. # 默认终端
  34. set -g default-terminal "xterm-256color"
  35. # Terminal overrides
  36. set -g set-clipboard on
  37. set -g terminal-overrides "*88col*:colors=88,*256col*:colors=256,xterm*:colors=256,*256col*:Tc,*:Ms"
  38. # 这个不能关,关了进了 vim 再退出屏幕画面不会恢复到进入之前
  39. setw -g alternate-screen on
  40. # }}}
  41. ########## 状态栏设置 ---{{{
  42. #
  43. # 开启状态栏,并在接下来定制状态栏样式
  44. set -g status on
  45. # 不关心其它窗口的事件,对强迫症来说太烦人了
  46. setw -g monitor-activity off
  47. # 每隔 10 秒刷新一次状态栏
  48. set -g status-interval 10
  49. # 状态栏的窗口列表靠左显示
  50. set -g status-justify left
  51. # 状态栏的整体色调背景色为蓝色
  52. set -g status-style bg=#0000AA
  53. # 状态栏左部最大长度不超过 32
  54. set -g status-left-length 32
  55. # 状态栏左部的格式: 亮品红的日期时间,然后是亮黄色的主机名(#h)
  56. set -g status-left "#[fg=magenta,bold]%m-%d %H:%M #[fg=brightyellow,bold]#h #[fg=red,bold]| "
  57. # 状态栏右部最大长度不超过 32
  58. set -g status-right-length 32
  59. # 状态栏右部显示内容
  60. set -g status-right "#[fg=brightyellow]| #(tmux-ui LOGO)#[default]"
  61. # 状态栏窗口列表中,每个窗口的显示格式: 绿色的编号(#I)及窗口名称(#W)
  62. setw -g window-status-format '#[fg=green]#I-#(tmux-ui WIN #{pane_title})#[default]'
  63. # 状态栏窗口列表中,当前窗口的显示格式: 黄色的编号(#I)及窗口名称(#W)
  64. setw -g window-status-current-format '#[fg=brightyellow]#I-#(tmux-ui WIN #{pane_title})#[default]'
  65. # 状态栏窗口列表中,有事件的窗口的显示风格
  66. setw -g window-status-activity-style fg=red,bold,bg=default
  67. # 状态栏窗口列表中,有喇叭的窗口的显示风格
  68. setw -g window-status-bell-style fg=red,bold,bg=default
  69. # Pane 的边框格式
  70. set -g pane-border-format '#(tmux-ui PANE #{pane_title} #{pane_active} #{pane_width})'
  71. # 固定给每个 pane 顶部显示一个边框
  72. set -g pane-border-status top
  73. # 设置边框颜色
  74. set -g pane-active-border-style "bg=colour236,fg=cyan bold"
  75. set -g pane-border-style "bg=colour234,fg=white"
  76. # tmux 的信息也会显示在状态栏,包括 tmux 的命令行
  77. set -g message-style fg=brightyellow,bold,bg=red
  78. # 设置信息显示时间
  79. set -g display-time 1000
  80. # }}}
  81. ########## 窗口管理 ---{{{
  82. #
  83. # 窗口的索引值从 0 开始
  84. set -g base-index 0
  85. # 关闭中间的会自动重新编号
  86. # set -g renumber-windows on
  87. set -g detach-on-destroy off
  88. # 类似于 screen,用 Ctrl+C 创建窗口,故意映射两组,防止按错
  89. bind-key C-c new-window -c '#{pane_current_path}'
  90. bind-key c new-window -c '#{pane_current_path}'
  91. # 自动设置窗口标题,一旦主动设置过窗口标题,则此窗口不会再次自动设置名称
  92. setw -g automatic-rename on
  93. # 通过 Ctrl+n / Ctrl+p 来切换窗口
  94. bind-key C-n next-window
  95. bind-key n next-window
  96. bind-key C-p previous-window
  97. bind-key p previous-window
  98. # 快速在两个窗口之间切换
  99. bind-key C-a last-window
  100. # 显示所有窗口,以供跳转
  101. unbind-key l
  102. bind-key l choose-window
  103. bind-key k if-shell 'rm tmux/secret 2>/dev/null && exit 0 || touch tmux/secret && exit 1' {
  104. setw -g window-status-format '#[fg=green]#I-#(tmux-ui WIN #{pane_title})#[default]'
  105. } {
  106. # 但如果是隐私模式则只显示星号
  107. setw -g window-status-format '#[fg=green]#I-****#[default]'
  108. }
  109. bind-key K if-shell 'rm tmux/secret 2>/dev/null && exit 0 || touch tmux/secret && exit 1' {
  110. setw -g window-status-format '#[fg=green]#I-#(tmux-ui WIN #{pane_title})#[default]'
  111. setw -g window-status-current-format '#[fg=brightyellow]#I-#(tmux-ui WIN #{pane_title})#[default]'
  112. set -g pane-border-format '#(tmux-ui PANE #{pane_title} #{pane_active} #{pane_width})'
  113. } {
  114. # 但如果是隐私模式则只显示星号
  115. setw -g window-status-format '#[fg=green]#I-****#[default]'
  116. setw -g window-status-current-format '#[fg=brightyellow]#I-****#[default]'
  117. set -g pane-border-format ''
  118. }
  119. # }}}
  120. ########## 面板管理 ---{{{
  121. #
  122. # 显示面板编号,方便跳转,以及通过样式得知哪个是当前面板
  123. bind-key m display-pane
  124. bind-key C-m display-pane
  125. set -g display-panes-time 3000
  126. set -g display-panes-active-colour brightblack
  127. set -g display-panes-colour brightyellow
  128. # 通过 | 和 - 来切分窗口
  129. unbind %
  130. unbind '"'
  131. bind | split-window -h -c '#{pane_current_path}'
  132. bind - split-window -v -c '#{pane_current_path}'
  133. bind-key o last-pane
  134. bind-key C-o last-pane
  135. bind-key w select-pane -t :.+
  136. bind-key Tab select-pane -t :.+
  137. # }}}