Skip to content

Commit 883959e

Browse files
committed
refactor(tmux): optimize content structure
1 parent 006cc23 commit 883959e

1 file changed

Lines changed: 162 additions & 122 deletions

File tree

tmux/tmux.conf

Lines changed: 162 additions & 122 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
# 2. 下面注释中的所有快捷键, 都是必须先按 ctrl a 松手后再需要按的.
1414

1515

16-
# --- 安装步骤 {{
16+
# --- 安装步骤 Installation {{
1717

1818
# 以 MacOS 举例:
1919
# 1) brew install tmux
@@ -24,28 +24,21 @@
2424
# }}
2525

2626

27-
# --- 基础配置 {{
27+
# --- 基础配置 Basic {{
2828

2929
# 将系统环境变量 $PATH 的值添加到这里,
3030
# 解决 '~/.tmux/plugins/tpm/tpm returned 1' 等找不到相关命令的问题.
3131
# doc: https://github.com/tmux-plugins/tpm/blob/master/docs/tpm_not_working.md
3232
set-environment -g PATH "$HOME/.dotfiles/bin:\
3333
/usr/local/opt/node@14/bin:\
3434
/usr/local/opt/python3/bin:\
35-
/Users/xg/go/bin:\
35+
$HOME/go/bin:\
3636
/usr/local/bin:\
3737
/usr/sbin:\
3838
/usr/bin:\
3939
/sbin:\
4040
/bin"
4141

42-
# r source 加载配置文件 ~/.tmux.conf, 使立即生效.
43-
bind r source-file ~/.tmux.conf \; display '~/.tmux.conf sourced'
44-
45-
# e 新创建一个 tmux 窗口来打开 ~/.tmux.conf, 保存后会自动对配置文件进行 source.
46-
bind e new-window -n "~/.tmux.conf" "\${EDITOR:-vim} ~/.tmux.conf &&
47-
tmux source ~/.tmux.conf && tmux display \"~/.tmux.conf sourced\""
48-
4942
# 添加新的 prefix 键: ctrl a, 默认的 ctrl b 不取消, 不推荐.
5043
#set -g prefix2 C-a
5144
#bind C-a send-prefix -2
@@ -84,103 +77,49 @@ set -g history-limit 50000
8477
# 支持使用鼠标切换窗口, 调整窗格大小等.
8578
set -g mouse on
8679

87-
# 窗口和窗格编号从 1 开始, 默认是从 0 开始.
88-
set -g base-index 1
89-
setw -g pane-base-index 1
90-
91-
# 窗口自动重命名.
92-
setw -g automatic-rename on
93-
94-
# 如果有窗口关闭, 对现有窗口进行重新编号.
95-
set -g renumber-windows on
96-
9780
# 终端标签页设置标题.
9881
set -g set-titles on
9982

100-
# 窗格编号的展示时间, 比如 q 命令展示的窗格编号的显示时长, 单位毫秒,
101-
# 按 esc 可随时退出窗格编号的展示.
102-
# NOTE:
103-
# q 命令显示所有窗格的数字编号后, 再按想跳转到的窗格的数字编号即可完成光标跳转,
104-
# 不过需要注意, 如果窗格数量大于等于 10 后, 10 以及 10 以上的窗格就不能通过这种
105-
# 方式做光标跳转了.
106-
set -g display-panes-time 3000
107-
108-
# 设置状态栏消息展示的时间, 单位毫秒.
109-
set -g display-time 600
110-
111-
# 监控窗口活动, 活动的窗口在状态栏高亮显示.
112-
set -g monitor-activity on
113-
114-
# 窗口活动信息使用在状态栏显示信息的方式替代响铃的方式.
115-
set -g visual-activity on
116-
117-
# }}
118-
119-
120-
# --- 窗口窗格操作按键映射 {{
121-
122-
# ctrl c 创建新的 session.
123-
bind C-c new-session
124-
125-
# meta(alt/option) f 输入关键字, 搜索 session.
126-
bind M-f command-prompt -p find-session 'switch-client -t %%'
127-
128-
# k/j/h/l 光标向上/下/左/右边的窗格跳转.
129-
bind -r k select-pane -U
130-
bind -r j select-pane -D
131-
bind -r h select-pane -L
132-
bind -r l select-pane -R
133-
134-
# >/< 和下一个/上一个窗格交换位置.
135-
bind > swap-pane -D
136-
bind < swap-pane -U
137-
138-
# H/J/K/L 向左/下/上/右 resize 窗格.
139-
bind -r H resize-pane -L 2
140-
bind -r J resize-pane -D 2
141-
bind -r K resize-pane -U 2
142-
bind -r L resize-pane -R 2
83+
# prefix : 进入 command 模式后, 使用 vi 的键映射, 默认 emacs.
84+
set -g status-keys vi
14385

144-
# ctrl l 清空窗格屏幕的同时, 窗格的历史记录也被清除.
145-
# NOTE: 注意和不加 prefix 的 ctrl l 的区别, 不加 prefix 的 ctrl l 只清空当前窗格的屏幕,
146-
# 窗格的历史内容记录还是保留的, 可以通过进入 copy 模式后进行浏览.
147-
bind C-l send-keys C-l \; run 'sleep 0.1' \; clear-history
86+
# prefix [ 进入 copy 模式后, 使用 vi 的键映射, 默认 emacs.
87+
setw -g mode-keys vi
14888

14989
# }}
15090

15191

152-
# --- Copy 模式和 Sync 模式配置 {{
92+
# --- 窗格配置 Panes Customization {{
15393

154-
# copy 模式下, 使用 vi 或 emacs 的键位绑定, 默认值: emacs
155-
# NOTE: 通过 [ 进入到 copy 模式, 按 q 可退出 copy 模式.
156-
set -g status-keys vi
157-
setw -g mode-keys vi
158-
159-
# copy 模式下, 使用 v 进行文本选择, 使用 V 可进行按行选择.
160-
bind -T copy-mode-vi v send-keys -X begin-selection
161-
162-
# copy 模式下, 使用 ctrl v 进行矩形选择, 按完 ctrl v 后, 需要再按 v 进行选择.
163-
bind -T copy-mode-vi C-v send -X rectangle-toggle
94+
# 窗格编号从 1 开始, 默认是从 0 开始.
95+
setw -g pane-base-index 1
16496

165-
# copy 模式下, 使用 y 将选择的文本拷贝到系统剪贴板;
166-
# 如果安装了 tmux-plugins/tmux-yank 插件, 这条可以不配置.
167-
bind -T copy-mode-vi y send-keys -X copy-selection-and-cancel
97+
# 窗格边框颜色.
98+
set -g pane-border-style fg=colour244
16899

169-
# ctrl y 打开/关闭 sync 模式, 进入 sync 模式后, 如果一个窗口有多个窗格,
170-
# 在其中一个窗格执行命令, 其他窗格同时会执行该命令, 被 t 时间覆盖的窗格除外.
171-
# NOTE: 不要使用 bind -n C-y 这种方式, 加 -n 表示不需要 prefix 前缀, 会导致 vim 的 ctrl y 快捷键无法使用.
172-
bind C-y setw synchronize-panes
100+
# 当前活动窗格边框颜色.
101+
set -g pane-active-border-style fg=blue
173102

174-
# }}
103+
# 窗格序号的颜色设置.
104+
set -g display-panes-colour colour33
175105

106+
# 活动窗格序号的颜色设置.
107+
set -g display-panes-active-colour colour166
176108

177-
# --- 主题颜色配置 {{
109+
# 窗格序号的展示时间, 比如 q 命令展示的窗格编号的显示时长, 单位毫秒,
110+
# 按 esc 可随时退出窗格编号的展示.
111+
# NOTE:
112+
# q 命令显示所有窗格的数字编号后, 再按想跳转到的窗格的数字编号即可完成光标跳转,
113+
# 不过需要注意, 如果窗格数量大于等于 10 后, 10 以及 10 以上的窗格就不能通过这种
114+
# 方式做光标跳转了.
115+
set -g display-panes-time 3000
178116

179-
# 窗口名称的颜色设置, 在状态栏显示.
180-
setw -g window-status-style fg=colour244,bg=default,dim
117+
# t 时钟的颜色设置.
118+
setw -g clock-mode-colour green
181119

182-
# 当前活动窗口名称的颜色设置.
183-
setw -g window-status-current-style fg=colour166,bg=default,bright
120+
# 设置时钟的显示格式, 12 小时或 24 小时.
121+
# Default: 24
122+
set -g clock-mode-style 24
184123

185124
# 显示窗格的名称并确定显示的位置, 可选值: top, bottom
186125
set -g pane-border-status top
@@ -198,49 +137,78 @@ set-hook -g 'pane-exited' 'run-shell -b "
198137
set-hook -g 'after-split-window' 'run-shell -b "
199138
if [ \#{window_panes} -gt 1 ]; then tmux set pane-border-status top; fi"'
200139

201-
# 窗格边框颜色.
202-
set -g pane-border-style fg=colour244
203-
204-
# 当前活动窗格边框颜色.
205-
set -g pane-active-border-style fg=blue
140+
# }}
206141

207-
# 窗格序号的颜色设置.
208-
set -g display-panes-colour colour33
209142

210-
# 活动窗格序号的颜色设置.
211-
set -g display-panes-active-colour colour166
143+
# --- 状态栏配置 Statusline Customization {{
212144

213-
# 消息的颜色设置.
214-
set -g message-style bg=colour235,fg=colour166
145+
# 新建 session 时, 是否默认开启状态栏.
146+
# 默认值: on, 可选值: off, 2, 3, 4, 5 or more
147+
set -g status on
215148

216-
# t 时钟的颜色设置.
217-
setw -g clock-mode-colour green
149+
# 状态栏的位置.
150+
# 默认值: bottom, 可选值: top
151+
set -g status-position top
218152

219-
# 新建 session 时, 是否默认开启状态栏, 默认值: on, 可选值: off
220-
set -g status on
153+
# 状态栏颜色设置.
154+
set -g status-style bg=colour235,fg=colour136,default
221155

222156
# 重绘状态栏的间隔秒数, 默认 15 秒.
223157
set -g status-interval 1
224158

225-
# 状态栏的位置, 默认值: bottom, 可选值: top
226-
set -g status-position top
159+
# 状态栏上出现的消息的颜色设置.
160+
set -g message-style bg=colour235,fg=colour166
227161

228-
# 状态栏信息位置调整, 默认值: left, 可选值: centre, right
229-
set -g status-justify left
162+
# 设置状态栏消息展示的时间, 单位毫秒.
163+
set -g display-time 600
230164

231-
# 状态栏颜色设置.
232-
set -g status-style bg=colour235,fg=colour136,default
165+
# *** status-left {{
233166

234167
# 状态栏左边信息的显示长度.
235168
set -g status-left-length 40
236169

170+
# status-left 状态栏左边显示的信息定制.
171+
# #S Name of session
172+
set -g status-left "#[fg=#CE0000,bold]  #S "
173+
174+
# }}
175+
176+
# *** window list {{
177+
178+
# 窗口名称列表栏的位置调整, 默认值: left, 可选值: centre, right
179+
set -g status-justify left
180+
181+
# 是否允许更改窗口名.
182+
set -wg allow-rename on
183+
184+
# 是否允许窗口自动重命名.
185+
set -wg automatic-rename off
186+
187+
# 窗口编号从 1 开始, 默认是从 0 开始.
188+
set -g base-index 1
189+
190+
# 如果有窗口关闭, 对现有窗口进行重新编号.
191+
set -g renumber-windows on
192+
193+
# 监控窗口活动, 活动的窗口在状态栏高亮显示.
194+
set -g monitor-activity on
195+
196+
# 窗口活动信息使用在状态栏显示信息的方式替代响铃的方式.
197+
set -g visual-activity on
198+
199+
# 窗口名称的颜色设置.
200+
setw -g window-status-style fg=colour244,bg=default,dim
201+
202+
# 当前活动窗口名称的颜色设置.
203+
setw -g window-status-current-style fg=colour166,bg=default,bright
204+
205+
# }}
206+
207+
# *** status-right {{
208+
237209
# 状态栏右边信息的显示长度.
238210
set -g status-right-length 180
239211

240-
# 状态栏左边显示的信息定制.
241-
set -g status-left "#[fg=#CE0000,bold]  #S "
242-
243-
# 状态栏右边显示的信息定制.
244212
set -g status-right "#{prefix_highlight} \
245213
#[fg=orange,bold]#{iptmthd} \
246214
#[fg=#ff5f5f,bold] #{current_colorscheme} #[fg=#ff5f87]#{current_opacity} \
@@ -254,11 +222,19 @@ set -g status-right "#{prefix_highlight} \
254222
#{moon_phase_icon} \
255223
#[fg=#009393]⌚️%a %m-%d %H:%M:%S"
256224

257-
# b 显示或隐藏当前 session 的状态栏.
258-
bind b set status
225+
# }}
259226

260-
# ctrl b 显示或隐藏当前窗格的所有窗格的名称.
261-
bind C-b set pane-border-status
227+
# }}
228+
229+
230+
# --- 快捷键绑定 Key Bindings {{
231+
232+
# r source 加载配置文件 ~/.tmux.conf, 使立即生效.
233+
bind r source-file ~/.tmux.conf \; display '~/.tmux.conf sourced'
234+
235+
# e 新创建一个 tmux 窗口来打开 ~/.tmux.conf, 保存后会自动对配置文件进行 source.
236+
bind e new-window -n "~/.tmux.conf" "\${EDITOR:-vim} ~/.tmux.conf &&
237+
tmux source ~/.tmux.conf && tmux display \"~/.tmux.conf sourced\""
262238

263239
# v 随机更换 Vim/Neovim 和 Alacritty 的 colorscheme.
264240
bind v run 'random-colorscheme'
@@ -275,10 +251,58 @@ bind C-k run 'decrease-opacity'
275251
# ctrl j 降低 Alacritty 的透明度.
276252
bind C-j run 'increase-opacity'
277253

254+
# b 显示或隐藏当前 session 的状态栏.
255+
bind b set status
256+
257+
# ctrl b 显示或隐藏当前窗格的所有窗格的名称.
258+
bind C-b set pane-border-status
259+
260+
# ctrl l 清空窗格屏幕的同时, 窗格的历史记录也被清除.
261+
# NOTE: 注意和不加 prefix 的 ctrl l 的区别, 不加 prefix 的 ctrl l 只清空当前窗格的屏幕,
262+
# 窗格的历史内容记录还是保留的, 可以通过进入 copy 模式后进行浏览.
263+
bind C-l send-keys C-l \; run 'sleep 0.1' \; clear-history
264+
265+
# copy 模式下, 使用 v 进行文本选择, 使用 V 可进行按行选择.
266+
bind -T copy-mode-vi v send-keys -X begin-selection
267+
268+
# copy 模式下, 使用 ctrl v 进行矩形选择, 按完 ctrl v 后, 需要再按 v 进行选择.
269+
bind -T copy-mode-vi C-v send -X rectangle-toggle
270+
271+
# copy 模式下, 使用 y 将选择的文本拷贝到系统剪贴板;
272+
# 如果安装了 tmux-plugins/tmux-yank 插件, 这条可以不配置.
273+
bind -T copy-mode-vi y send-keys -X copy-selection-and-cancel
274+
275+
# ctrl y 打开/关闭 sync 模式, 进入 sync 模式后, 如果一个窗口有多个窗格,
276+
# 在其中一个窗格执行命令, 其他窗格同时会执行该命令, 被 t 时间覆盖的窗格除外.
277+
# NOTE: 不要使用 bind -n C-y 这种方式, 加 -n 表示不需要 prefix 前缀, 会导致 vim 的 ctrl y 快捷键无法使用.
278+
bind C-y setw synchronize-panes
279+
280+
# ctrl c 创建新的 session.
281+
bind C-c new-session
282+
283+
# meta(alt/option) f 输入关键字, 搜索 session.
284+
bind M-f command-prompt -p find-session 'switch-client -t %%'
285+
286+
# k/j/h/l 光标向上/下/左/右边的窗格跳转.
287+
bind -r k select-pane -U
288+
bind -r j select-pane -D
289+
bind -r h select-pane -L
290+
bind -r l select-pane -R
291+
292+
# >/< 和下一个/上一个窗格交换位置.
293+
bind > swap-pane -D
294+
bind < swap-pane -U
295+
296+
# H/J/K/L 向左/下/上/右 resize 窗格.
297+
bind -r H resize-pane -L 2
298+
bind -r J resize-pane -D 2
299+
bind -r K resize-pane -U 2
300+
bind -r L resize-pane -R 2
301+
278302
# }}
279303

280304

281-
# --- 插件管理与配置 {{
305+
# --- 插件管理与配置 Plugins {{
282306

283307
# *** 安装插件管理工具:
284308
# git clone https://github.com/tmux-plugins/tpm ~/.tmux/plugins/tpm
@@ -477,7 +501,7 @@ run '~/.tmux/plugins/tpm/tpm'
477501
# }}
478502

479503

480-
# --- 使用技巧 {{
504+
# --- 使用技巧 Tips {{
481505

482506
# ctrl a prefix 按键, 以下所有按键如果没有特殊说明, 都必须先按 prefix,
483507
# 注意按完 prefix, 需要先松开按键, 再按其他的具体命令按键.
@@ -514,6 +538,22 @@ run '~/.tmux/plugins/tpm/tpm'
514538
# w 列出所有 session 的所有窗口.
515539
# f 输入关键字搜索窗口.
516540
#
541+
# **** 窗口状态的标记符号释义 ****
542+
# * Denotes the current window.
543+
# 表示当前工作窗口.
544+
# - Marks the last window (previously selected).
545+
# 表示上一次所在的窗口.
546+
# # Window is monitored and activity has been detected.
547+
# 检测到窗口有信息.
548+
# ! A bell has occurred in the window.
549+
# 检测到窗口有铃声响起.
550+
# ~ The window has been silent for the monitor-silence interval.
551+
# 窗口在监视器静默间隔内静默.
552+
# M The window contains the marked pane.
553+
# 窗口中存在被标记的窗格.
554+
# Z The window's active pane is zoomed.
555+
# 窗口中有正在处于被缩放状态的窗格.
556+
#
517557
# **** 窗格管理 ****
518558
# % 划分左右两个窗格.
519559
# " 划分上下两个窗格.

0 commit comments

Comments
 (0)