forked from infokiller/config-public
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.tmux.conf
621 lines (541 loc) · 30.6 KB
/
.tmux.conf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
################################################################################
# General settings #
################################################################################
# NOTE for `set` options below:
# -g means to set the option globally to all sessions and windows.
# -a means to append instead of overriding the variable.
# I used to set this to screen-256color, but using tmux-256color fixed italic
# fonts.
set -s default-terminal 'tmux-256color'
# NOTE: Using `SHELL` to set the default shell is more robust than using
# `default-shell`, because if the shell defined is invalid (for example, points
# to a non-existent executable), tmux will fall back to another shell in the
# former case, but not in the latter. In addition, the tmux man page says that
# this option should be configured when tmux is used as a login shell, which is
# not the case for me.
# I used to set `default-shell` to zsh as below, however this is less
# robust than setting the `SHELL` environment variable, since
# set -g default-shell /bin/zsh
setenv -g SHELL /bin/zsh
# tmux first executes `default-shell` as a login shell, and only then
# executes `default-command`. Therefore, if both are set to zsh, zshenv will be
# read twice (once for the login shell, then a second time for the
# default-command). To avoid this, I'm now not setting `default-command`.
# set -g default-command /bin/zsh
# Set SSH_AUTH_SOCK to a static path that we can control dynamically by
# symlinking from it. See: https://gist.github.com/martijnvermaat/8070533
setenv -g SSH_AUTH_SOCK "$HOME/.ssh/ssh_auth_sock"
# Clear existing values to avoid cluttering the update-environment option with
# duplicates when this file is sourced again.
set -gu update-environment
# Set COLORTERM from the terminal when attaching to a session.
set -ga update-environment COLORTERM
# Set VTE_VERSION from the terminal when attaching to a session. Useful for
# truecolor detection in VTE terminals.
set -ga update-environment VTE_VERSION
# Clear existing values to avoid cluttering the update-environment option with
# duplicates when this file is sourced again.
set -su terminal-overrides
# Enable terminal scrolling [1] and keep support for terminal titles [2]. We
# set it only for xterm-termite and not xterm-* because in kitty this setting
# causes issues with scrolling [3].
# [1] https://wiki.archlinux.org/index.php/tmux#Scrolling_issues
# [2] https://unix.stackexchange.com/questions/75216/tmux-set-titles-doesnt-work
# [3] https://github.com/kovidgoyal/kitty/issues/249#issuecomment-620356958
# TODO: Fix kitty keyboard scrolling in tmux using
# ctrl+shift+{i,k,pageup,pagedn}.
set -sa terminal-overrides ',xterm-termite:XT:smcup@:rmcup@'
set -sa terminal-overrides ',rxvt*:XT:smcup@:rmcup@'
# Enable unofficial extensions to terminfo:
# - 24-bit color (Tc)
# - Overline (Smol)
# - Styled underline (Smulx)
# - Colored underline (Setulc)
#
# To test these settings, run terminal-capabilities-test.
#
# NOTE: cursor color (Cs, Cr) and cursor style (Ss, Se) work out of the box for
# me in kitty, termite, and gnome terminal, so they are not set here.
#
# References:
# - The TERMINO EXTENSIONS section of man tmux(1)
# - https://wiki.archlinux.org/index.php/tmux#24-bit_color
# - https://github.com/tmux/tmux/issues/1492#issuecomment-427939241
# - https://github.com/tmux/tmux/pull/1771#issuecomment-500906522
#
# NOTE: I used to enable this selectively for xterm-kitty and xterm-termite, but
# also wanted to enable it for gnome-terminal which reports a $TERM of
# xterm-256color, and I didn't to repeat this for the third time. If this will
# cause an issue, I will consider reverting back to copy pasting or setting this
# from a shell script.
set -sa terminal-overrides ',xterm-*:Tc'
set -sa terminal-overrides ',xterm-*:Smulx=\E[4::%p1%dm'
set -sa terminal-overrides ',xterm-*:Setulc=\E[58::2::%p1%{65536}%/%d::%p1%{256}%/%{255}%&%d::%p1%{255}%&%d%;m'
# Make ctrl+{left,right} work
# http://superuser.com/questions/360832/how-can-i-make-ctrlleft-right-keys-work-right-in-tmux
set -wg xterm-keys on
# When available, request focus events from the terminal.
set -s focus-events on
set -g set-titles on
# Set titles to something informative that is easily parsable for future data
# analysis.
# NOTE: before 2020-06-02 the format was:
# 'client_termname:#{client_termname} #$# session_name:#{session_name} #$# pane_current_command:#{pane_current_command} #$# pane_title:#{pane_title} #$# pane_current_path:#{pane_current_path} #$# window_name:#{window_name}'
# I changed it to be much less verbose because it was not readable when the
# window titles were shown. When I analyze the data in the future, I will need
# to support both formats.
# Options for separators:
# NOTE: I wanted to make the first sections in the terminal title constant width
# to align them between multiple terminal windows, however this has a few
# issues:
# - It requires a monospace font for window titles which was ugly when I tried
# it.
# - Before version 3.2, tmus didn't support padding a nested variable like
# `{p12:#{=/20/...:pane_current_command}}` [1].
# - Kitty compresses whitespace in the titles [2]
# [1] https://github.com/tmux/tmux/issues/2434
# [2] https://github.com/kovidgoyal/kitty/issues/3062
set -g set-titles-string '#{?#{==:#(tmux show-environment -t #{q:session_name} SSH_CONNECTION),-SSH_CONNECTION},,力 #{host_short} }#{session_name} #{?#{!=:#{window_name},#{=/20/...:pane_current_command}},#{window_name} ,}#{=/20/...:pane_current_command} #{=/120/...:pane_title}'
# Enable the mouse. Not really used, other than occasional scrolling.
set -g mouse on
# Max scrollback size (number of lines).
set -g history-limit 500000
# Don't wrap around the end of the pane contents when searching.
set -wg wrap-search off
# Move status bar to the top.
set -g status-position top
# Refresh status line more often (default is 15 seconds).
set -g status-interval 5
# Display the hostname.
set -wg status-left '#{?#{==:#(tmux show-environment -t #{q:session_name} SSH_CONNECTION),-SSH_CONNECTION},,力#{host_short} }#{session_name} '
# Increase max length to 40 (default is 10).
set -wg status-left-length 40
# Show the hostname if connected via SSH and show if the prefix is active.
set -wg status-right '#{?#{==:#(tmux show-environment -t #{q:session_name} SSH_CONNECTION),-SSH_CONNECTION},,力#{host_short}} #{prefix_highlight}'
# Decrease max length to 20 (default is 40).
set -wg status-right-length 20
# Monitor windows for activity and highlight them if needed.
set -wg monitor-activity on
# Allow two clients in the same session to see a different size if they're on
# different windows.
set -wg aggressive-resize on
# Set the window size according to the client with the most recent activity.
set -wg window-size latest
# Rename window to the running command if their name is not explicitly set.
set -wg automatic-rename on
# Renumber windows when a window is closed.
set -g renumber-windows on
# See also: https://gist.github.com/bcremer/4491339
# Start numbering at 1
set -g base-index 1
# Same for panes.
set -wg pane-base-index 1
# Display messages for 5 seconds (default is 750 ms?)
set -g display-time 4000
################################################################################
# Keybindings: general settings #
################################################################################
# Don't wait for escape sequences in command sequences.
set -s escape-time 0
# Repeat time limit (ms)
set -g repeat-time 500
set -g status-keys emacs
# Unbind default keybindings for all servers not named "default-keybindings".
%if '#{!=:#{b:socket_path},default-keybindings}'
unbind -a -T root
unbind -a -T prefix
unbind -a -T copy-mode-vi
%endif
# Remap prefix key to Ctrl+Q
set-option -g prefix 'C-q'
bind -N 'Send tmux prefix' \
'C-q' \
send-prefix
set-option -g prefix2 None
# TODO: Add notes (using -N) and consistently format all bind commands.
################################################################################
# Keybindings: navigating panes/windows/sessions #
################################################################################
# Session and window navigation using Alt+Shift+ijkl.
bind -T root 'M-J' select-window -p
bind 'M-J' send-keys 'M-J'
bind -T copy-mode-vi 'M-J' select-window -p
bind -T root 'M-L' select-window -n
bind 'M-L' send-keys 'M-L'
bind -T copy-mode-vi 'M-L' select-window -n
bind -T root 'M-:' select-window -l
bind 'M-:' send-keys 'M-:'
bind -T copy-mode-vi 'M-:' select-window -l
bind -T root 'M-K' switch-client -p
bind 'M-K' send-keys 'M-K'
bind -T copy-mode-vi 'M-K' switch-client -p
bind -T root 'M-I' switch-client -n
bind 'M-I' send-keys 'M-I'
bind -T copy-mode-vi 'M-I' switch-client -n
# https://github.com/christoomey/vim-tmux-navigator
is_vim="ps -o state= -o comm= -t '#{pane_tty}' \
| grep -iqE '^[^TXZ ]+ +(\\S+\\/)?g?(view|n?vim?x?)(diff)?$'"
bind -T root 'M-j' if "$is_vim" 'send-keys M-j' 'select-pane -L'
bind -T root 'M-k' if "$is_vim" 'send-keys M-k' 'select-pane -D'
bind -T root 'M-i' if "$is_vim" 'send-keys M-i' 'select-pane -U'
bind -T root 'M-l' if "$is_vim" 'send-keys M-l' 'select-pane -R'
bind -T root 'M-;' run "($is_vim && tmux send-keys M-w) || (tmux select-pane -l || tmux select-window -l)"
# Same for copy mode.
bind -T copy-mode-vi 'M-j' select-pane -L
bind -T copy-mode-vi 'M-k' select-pane -D
bind -T copy-mode-vi 'M-i' select-pane -U
bind -T copy-mode-vi 'M-l' select-pane -R
bind -T copy-mode-vi 'M-;' run '(tmux select-pane -l || tmux select-window -l)'
# Enabling navigation with prefix to make sure it's always accessible from tmux
# even if there are bugs in the vim plugin.
bind 'M-j' select-pane -L
bind 'M-k' select-pane -D
bind 'M-i' select-pane -U
bind 'M-l' select-pane -R
bind 'M-;' select-pane -l
# Switch to windows by number (copied from default tmux bindings).
bind 0 select-window -t :=0
bind 1 select-window -t :=1
bind 2 select-window -t :=2
bind 3 select-window -t :=3
bind 4 select-window -t :=4
bind 5 select-window -t :=5
bind 6 select-window -t :=6
bind 7 select-window -t :=7
bind 8 select-window -t :=8
bind 9 select-window -t :=9
bind -N 'Switch to pane by name' \
f \
new-window 'tmux-select-pane | xargs --null --no-run-if-empty tmux-switch-pane'
bind -N 'Switch to pane by process' \
F \
new-window 'tmux-search-process'
bind -N 'Switch to pane with choose-tree (rich UI)' \
'C-f' \
choose-tree -Zw
bind 'C-z' suspend-client
# Select next/previous window by moving the mouse wheel when hovering over the
# status line (copied from default tmux bindings).
bind -T root WheelUpStatus previous-window
bind -T root WheelDownStatus next-window
# Select pane/window with a mouse click (copied from default tmux bindings).
bind -T root MouseDown1Pane select-pane -t = \; send-keys -M
bind -T root MouseDown1Status select-window -t =
################################################################################
# Keybindings: managing panes/windows/sessions #
################################################################################
# Splitting panes.
bind h split-window -h -c "#{pane_current_path}"
bind v split-window -v -c "#{pane_current_path}"
bind H split-window -h -c "$HOME"
bind V split-window -v -c "$HOME"
# Moving windows
bind -T root 'M-C-j' swap-window -t -1 \; select-window -t -1
bind 'M-C-j' send-keys 'M-C-j'
bind -T root 'M-C-l' swap-window -t +1 \; select-window -t +1
bind 'M-C-l' send-keys 'M-C-l'
# Same for copy mode
bind -T copy-mode-vi 'M-C-j' swap-window -t -1 \; select-window -t -1
bind -T copy-mode-vi 'M-C-l' swap-window -t +1 \; select-window -t +1
# Changing panes layout
bind -r 'M-n' select-layout -n
bind -r 'M-p' select-layout -p
bind 'M-1' select-layout even-horizontal
bind 'M-2' select-layout even-vertical
bind 'M-3' select-layout main-horizontal
bind 'M-4' select-layout main-vertical
bind 'M-5' select-layout tiled
# Moving panes in the current window and layout
bind -r '{' swap-pane -U
bind -r '}' swap-pane -D
bind -r 'J' swap-pane -U
bind -r 'L' swap-pane -D
bind -r 'I' rotate-window -U
bind -r 'K' rotate-window -D
# Marking/unmarking a pane (only one can be marked at any time).
bind m select-pane -m
bind M select-pane -M
# Moving panes between windows
bind s break-pane
bind S command-prompt -p 'send pane to:' "join-pane -t '%%'"
# bind J command-prompt -p 'join pane from:' "join-pane -s '%%'"
# Use Alt+f to maximize pane, consistent with i3.
bind -T root 'M-f' resize-pane -Z
bind 'M-f' send-keys 'M-f'
bind -T prefix 'M-f' resize-pane -Z
bind -T copy-mode-vi 'M-f' resize-pane -Z
# Resizing panes. The -r flag means that it is repeatable.
bind -r j resize-pane -L 5
bind -r k resize-pane -D 5
bind -r i resize-pane -U 5
bind -r l resize-pane -R 5
# Resize panes with a left mouse click drag (copied from default tmux bindings).
bind -T root 'MouseDrag1Border' resize-pane -M
# bind -T root M-f run ~/.tmux/plugins/tmux-copycat/scripts/copycat_search.sh
# bind f run ~/.tmux/plugins/tmux-copycat/scripts/copycat_search.sh
# Create new session/window (equivalent to Chrome window/tab) with n/t and
bind n new-session
bind c new-window -c '#{pane_current_path}'
bind C new-window -c "$HOME"
# Kill panes and windows
bind x confirm-before -p 'Kill pane?' 'kill-pane'
bind X confirm-before -p 'Kill window [#{window_name}]? (y/n)' 'kill-window'
# Rename session
bind -T root 'C-F2' command-prompt -p '(rename-session) ' -I "#{session_name}" "rename-session -- '%%'"
bind 'C-F2' send-keys 'C-F2'
bind -T copy-mode-vi 'C-F2' command-prompt -p '(rename-session) ' -I "#{session_name}" "rename-session -- '%%'"
# Rename window
bind -T root 'F2' command-prompt -p '(rename-window) ' -I "#{window_name}" "rename-window -- '%%'"
bind 'F2' send-keys 'F2'
bind -T copy-mode-vi 'F2' command-prompt -p '(rename-window) ' -I "#{window_name}" "rename-window -- '%%'"
# Detach from session
bind d detach-client
# Synchronize panes
bind 'M-s' if-shell -F '#{pane_synchronized}' \
'set synchronize-panes off' \
'set synchronize-panes on'
# Open a menu to manage panes/windows with a angle brackets (copied from default
# tmux bindings).
bind-key -T prefix < display-menu -T "#[align=centre]#{window_index}:#{window_name}" -x W -y S "Swap Left" l "swap-window -t:-1" "Swap Right" r "swap-window -t:+1" "#{?pane_marked_set,,-}Swap Marked" s swap-window Kill X kill-window Respawn R "respawn-window -k" "#{?pane_marked,Unmark,Mark}" m "select-pane -m" Rename n "command-prompt -I \"#W\" \"rename-window -- '%%'\"" "New After" w "new-window -a" "New At End" W new-window
bind-key -T prefix > display-menu -T "#[align=centre]#{pane_index} (#{pane_id})" -x P -y P "#{?mouse_word,Search For #[underscore]#{=/9/...:mouse_word},}" C-r "copy-mode -t=; send -Xt= search-backward \"#{q:mouse_word}\"" "#{?mouse_word,Type #[underscore]#{=/9/...:mouse_word},}" C-y "send-keys -l -- \"#{q:mouse_word}\"" "#{?mouse_word,Copy #[underscore]#{=/9/...:mouse_word},}" c "set-buffer -- \"#{q:mouse_word}\"" "#{?mouse_line,Copy Line,}" l "set-buffer -- \"#{q:mouse_line}\"" "Horizontal Split" h "split-window -h" "Vertical Split" v "split-window -v" "Swap Up" u "swap-pane -U" "Swap Down" d "swap-pane -D" "#{?pane_marked_set,,-}Swap Marked" s swap-pane Kill X kill-pane Respawn R "respawn-pane -k" "#{?pane_marked,Unmark,Mark}" m "select-pane -m" "#{?window_zoomed_flag,Unzoom,Zoom}" z "resize-pane -Z"
# Open a menu to manage panes/windows with a mouse right click (copied from
# default tmux bindings).
bind-key -T root MouseDown3Pane if-shell -F -t = "#{||:#{mouse_any_flag},#{pane_in_mode}}" "select-pane -t=; send-keys -M" "display-menu -t= -xM -yM -T \"#[align=centre]#{pane_index} (#{pane_id})\" '#{?mouse_word,Search For #[underscore]#{=/9/...:mouse_word},}' 'C-r' {copy-mode -t=; send -Xt= search-backward \"#{q:mouse_word}\"} '#{?mouse_word,Type #[underscore]#{=/9/...:mouse_word},}' 'C-y' {send-keys -l -- \"#{q:mouse_word}\"} '#{?mouse_word,Copy #[underscore]#{=/9/...:mouse_word},}' 'c' {set-buffer -- \"#{q:mouse_word}\"} '#{?mouse_line,Copy Line,}' 'l' {set-buffer -- \"#{q:mouse_line}\"} '' 'Horizontal Split' 'h' {split-window -h} 'Vertical Split' 'v' {split-window -v} '' 'Swap Up' 'u' {swap-pane -U} 'Swap Down' 'd' {swap-pane -D} '#{?pane_marked_set,,-}Swap Marked' 's' {swap-pane} '' 'Kill' 'X' {kill-pane} 'Respawn' 'R' {respawn-pane -k} '#{?pane_marked,Unmark,Mark}' 'm' {select-pane -m} '#{?window_zoomed_flag,Unzoom,Zoom}' 'z' {resize-pane -Z}"
bind-key -T root M-MouseDown3Pane display-menu -T "#[align=centre]#{pane_index} (#{pane_id})" -t = -x M -y M "#{?mouse_word,Search For #[underscore]#{=/9/...:mouse_word},}" C-r "copy-mode -t=; send -Xt= search-backward \"#{q:mouse_word}\"" "#{?mouse_word,Type #[underscore]#{=/9/...:mouse_word},}" C-y "send-keys -l -- \"#{q:mouse_word}\"" "#{?mouse_word,Copy #[underscore]#{=/9/...:mouse_word},}" c "set-buffer -- \"#{q:mouse_word}\"" "#{?mouse_line,Copy Line,}" l "set-buffer -- \"#{q:mouse_line}\"" "Horizontal Split" h "split-window -h" "Vertical Split" v "split-window -v" "Swap Up" u "swap-pane -U" "Swap Down" d "swap-pane -D" "#{?pane_marked_set,,-}Swap Marked" s swap-pane Kill X kill-pane Respawn R "respawn-pane -k" "#{?pane_marked,Unmark,Mark}" m "select-pane -m" "#{?window_zoomed_flag,Unzoom,Zoom}" z "resize-pane -Z"
bind-key -T root MouseDown3Status display-menu -T "#[align=centre]#{window_index}:#{window_name}" -t = -x W -y S "Swap Left" l "swap-window -t:-1" "Swap Right" r "swap-window -t:+1" "#{?pane_marked_set,,-}Swap Marked" s swap-window Kill X kill-window Respawn R "respawn-window -k" "#{?pane_marked,Unmark,Mark}" m "select-pane -m" Rename n "command-prompt -I \"#W\" \"rename-window -- '%%'\"" "New After" w "new-window -a" "New At End" W new-window
bind-key -T root MouseDown3StatusLeft display-menu -T "#[align=centre]#{session_name}" -t = -x M -y S Next n "switch-client -n" Previous p "switch-client -p" Renumber N "move-window -r" Rename n "command-prompt -I \"#S\" \"rename-session -- '%%'\"" "New Session" s new-session "New Window" w new-window
################################################################################
# Keybindings: copy mode #
################################################################################
# Set vi bindings for copy mode
set -wg mode-keys vi
# Enter/leave copy mode {{{ #
# Enter copy mode {{{ #
bind 'Escape' copy-mode
bind 'C-u' copy-mode -u
bind 'PPage' copy-mode -u
bind 'M-q' send-keys 'M-q'
# Alt+q to go directly to copy mode.
bind -T root 'M-q' copy-mode
# Mouse wheel up to go directly to copy mode (copied from default tmux
# bindings).
bind -T root WheelUpPane if-shell -F -t = '#{mouse_any_flag}' 'send-keys -M' "if -Ft= \"#{pane_in_mode}\" \"send-keys -M\" \"copy-mode -et=\""
# Mouse left click drag to copy selected cells (copied from default tmux
# bindings).
bind -T root MouseDrag1Pane if-shell -F -t = '#{mouse_any_flag}' "if -Ft= \"#{pane_in_mode}\" \"copy-mode -M\" \"send-keys -M\"" 'copy-mode -M'
bind -T copy-mode-vi q send-keys -X cancel
bind -T copy-mode-vi 'Escape' send-keys -X cancel
# bind -T copy-mode-vi Escape send-keys -X clear-selection
bind -T copy-mode-vi 'C-c' send-keys -X cancel
# }}} Enter/leave copy mode #
bind -T copy-mode-vi j send-keys -X cursor-left
bind -T copy-mode-vi k send-keys -X cursor-down
bind -T copy-mode-vi i send-keys -X cursor-up
bind -T copy-mode-vi l send-keys -X cursor-right
# Word navigation
bind -T copy-mode-vi w send-keys -X previous-word
bind -T copy-mode-vi W send-keys -X previous-space
bind -T copy-mode-vi e send-keys -X next-word-end
bind -T copy-mode-vi E send-keys -X next-space-end
bind -T copy-mode-vi 0 send-keys -X start-of-line
bind -T copy-mode-vi '^' send-keys -X back-to-indentation
bind -T copy-mode-vi '$' send-keys -X end-of-line
bind -T copy-mode-vi '%' send-keys -X next-matching-bracket
bind -T copy-mode-vi '{' send-keys -X previous-paragraph
bind -T copy-mode-vi '}' send-keys -X next-paragraph
bind -T copy-mode-vi 'C-d' send-keys -X halfpage-down
bind -T copy-mode-vi 'C-u' send-keys -X halfpage-up
bind -T copy-mode-vi 'Home' send-keys -X start-of-line
bind -T copy-mode-vi 'End' send-keys -X end-of-line
bind -T copy-mode-vi 'NPage' send-keys -X page-down
bind -T copy-mode-vi 'PPage' send-keys -X page-up
# Shift+PageUp to scroll buffer. TODO: This doesn't work.
# bind -T root S-PageUp copy-mode -u
# bind 'S-PPage' send-keys 'S-PPage'
bind -T copy-mode-vi 'C-e' send-keys -X -N 5 scroll-down
bind -T copy-mode-vi 'C-y' send-keys -X -N 5 scroll-up
bind -T copy-mode-vi 'Up' send-keys -X scroll-up
bind -T copy-mode-vi 'Down' send-keys -X scroll-down
bind -T copy-mode-vi 'WheelUpPane' select-pane \; send-keys -X -N 5 scroll-up
bind -T copy-mode-vi 'WheelDownPane' select-pane \; send-keys -X -N 5 scroll-down
bind -T copy-mode-vi g send-keys -X history-top
bind -T copy-mode-vi G send-keys -X history-bottom
bind -T copy-mode-vi ':' command-prompt -p "(goto line)" "send -X goto-line \"%%%\""
# Incremental search.
# bind -T copy-mode-vi '/' command-prompt -p "(search down)" "send -X search-forward \"%%%\""
bind -T copy-mode-vi '/' command-prompt -i -I '#{pane_search_string}' -p '(search up)' "send -X search-backward-incremental \"%%%\""
# bind -T copy-mode-vi '?' command-prompt -p "(search up)" "send -X search-backward \"%%%\""
bind -T copy-mode-vi '?' command-prompt -i -I '#{pane_search_string}' -p '(search down)' "send -X search-forward-incremental \"%%%\""
bind -T copy-mode-vi '*' send-keys -FX search-forward "#{copy_cursor_word}"
bind -T copy-mode-vi '#' send-keys -FX search-backward "#{copy_cursor_word}"
bind -T copy-mode-vi n send-keys -X search-again
bind -T copy-mode-vi N send-keys -X search-reverse
bind -T copy-mode-vi f command-prompt -1 -p "(jump forward)" "send -X jump-forward \"%%%\""
bind -T copy-mode-vi F command-prompt -1 -p "(jump backward)" "send -X jump-backward \"%%%\""
bind -T copy-mode-vi t command-prompt -1 -p "(jump to forward)" "send -X jump-to-forward \"%%%\""
bind -T copy-mode-vi T command-prompt -1 -p "(jump to backward)" "send -X jump-to-backward \"%%%\""
bind -T copy-mode-vi \; send-keys -X jump-again
bind -T copy-mode-vi , send-keys -X jump-reverse
bind -T copy-mode-vi BSpace send-keys -X cursor-left
# Repeating actions (copied from default tmux bindings).
bind -T copy-mode-vi 1 command-prompt -N -I 1 -p (repeat) "send -N \"%%%\""
bind -T copy-mode-vi 2 command-prompt -N -I 2 -p (repeat) "send -N \"%%%\""
bind -T copy-mode-vi 3 command-prompt -N -I 3 -p (repeat) "send -N \"%%%\""
bind -T copy-mode-vi 4 command-prompt -N -I 4 -p (repeat) "send -N \"%%%\""
bind -T copy-mode-vi 5 command-prompt -N -I 5 -p (repeat) "send -N \"%%%\""
bind -T copy-mode-vi 6 command-prompt -N -I 6 -p (repeat) "send -N \"%%%\""
bind -T copy-mode-vi 7 command-prompt -N -I 7 -p (repeat) "send -N \"%%%\""
bind -T copy-mode-vi 8 command-prompt -N -I 8 -p (repeat) "send -N \"%%%\""
bind -T copy-mode-vi 9 command-prompt -N -I 9 -p (repeat) "send -N \"%%%\""
bind -T copy-mode-vi v send-keys -X begin-selection
bind -T copy-mode-vi V send-keys -X select-line
bind -T copy-mode-vi 'C-v' send-keys -X rectangle-toggle
bind -T copy-mode-vi y {
send-keys -X copy-selection
run -b 'tmux show-buffer | xsel --input --clipboard'
}
bind -T copy-mode-vi Enter {
# NOTE: I previously used copy-selection-and-cancel but at some point it
# caused an issue with the wrong content.
send-keys -X copy-selection
run -b '{ tmux show-buffer | xsel --input --clipboard; } || true'
send-keys -X cancel
}
# Copy to end of line, consistent with VIM.
# NOTE: copy-end-of-line is not used because it leaves copy mode.
bind -T copy-mode-vi Y {
send-keys -X begin-selection
send-keys -X end-of-line
send-keys -X copy-selection
run -b 'tmux show-buffer | xsel --input --clipboard'
}
# Open selected text.
bind -T copy-mode-vi o send-keys -X copy-pipe-and-cancel "cd #{pane_current_path}; sed 's%^~%${HOME}%' | xargs -I {} tmux new-window sensible-open {}"
# Search selected text.
bind -T copy-mode-vi s send-keys -X copy-pipe-and-cancel "xargs -I {} sensible-browser 'https://www.google.com/search?q={}'"
bind -T copy-mode-vi MouseDown1Pane select-pane
bind -T copy-mode-vi MouseDrag1Pane select-pane \; send-keys -X begin-selection
bind -T copy-mode-vi MouseDragEnd1Pane send-keys -X copy-selection-and-cancel
bind -T copy-mode-vi DoubleClick1Pane select-pane \; send-keys -X select-word
bind -T copy-mode-vi TripleClick1Pane select-pane \; send-keys -X select-line
################################################################################
# Keybindings: misc #
################################################################################
bind -N 'Reload tmux.conf' \
'R' \
source-file ~/.tmux.conf \; display-message 'Reloaded!'
bind ':' command-prompt
# TODO: Use `list-keys -N` once all keys have notes.
# NOTE: I tried displaying the menu in the center of the screen, but the `-x`
# and `-y` params don't support it directly. Since they also don't expand
# formats, I can't use something like `#{window_height}`, although I can write a
# shell script the uses it.
bind '?' display-menu -T '#[align=centre]Help' -x W -y S \
'List keys' k 'list-keys' \
'Edit config' e 'new-window "${EDITOR}" -c ":vert Man tmux | wincmd h" "${HOME}/.tmux.conf"' \
'Manpage' m 'new-window man tmux'
bind p paste-buffer
bind P choose-buffer -Z
bind -N 'Scrollback completion in all panes' \
-T root 'M-Tab' \
run "tmux split-window -p 40 'tmux send-keys -t #{pane_id} -- \"$(tmux-list-words --all --scroll 1000 --min 5 | fzf --multi | paste -sd\\ -)\"'"
bind -N 'Send Alt-Tab' \
'M-Tab' \
send-keys 'M-Tab'
bind -N 'Scrollback completion in current pane' \
-T root 'M-`' \
run "tmux split-window -p 40 'tmux send-keys -t #{pane_id} -- \"$(tmux-list-words --scroll 1000 --min 5 | fzf --multi | paste -sd\\ -)\"'"
bind -N 'Send Alt-`' \
'M-`' \
send-keys 'M-`'
bind -N 'File completion with locate' \
-T root 'M-C-f' \
run "tmux split-window -p 40 'tmux send-keys -t #{pane_id} \"$(locate / | fzf -m | paste -sd\\ -)\"'"
bind -N 'Send Ctrl-Alt-f' \
'M-C-f' \
send-keys 'M-C-f'
bind -N 'Select from visible URLs in current pane' \
u \
run -b 'tmux-open-pane-urls || true'
bind -N 'Select from all URLs in current pane' \
U \
run -b 'tmux-open-pane-urls -S - -E - || true'
bind -N 'Edit paths from pane' \
e \
run -b 'cd #{pane_current_path} && (tmux-select-pane-paths | xargs -d "\n" --no-run-if-empty tmux new-window "${EDITOR:-vim}")'
bind -N 'Copy paths from pane' \
E \
run -b 'cd #{pane_current_path} && (tmux-copy-pane-paths || true)'
bind -N 'Open pane content in editor' \
'C-e' \
run -b 'tmux-edit-pane-content'
bind -N 'Copy shell prompt buffer' \
y \
send-keys 'C-q' y
################################################################################
# Keybindings: unused commands #
################################################################################
# The following commented out keybindings contain defaults that use commands
# that I don't use elsewhere in my config. They were generated by executing
# `tmux list-keys` on 2020-07-09 with tmux 3.1b and then manually deleting all
# keybindings that invoke commands that I already use.
# TODO: Review and consider using these commands.
# bind-key -T copy-mode C-g send-keys -X clear-selection
# bind-key -T copy-mode-vi A send-keys -X append-selection-and-cancel
# bind-key -T copy-mode-vi H send-keys -X top-line
# bind-key -T copy-mode-vi L send-keys -X bottom-line
# bind-key -T copy-mode-vi M send-keys -X middle-line
# bind-key -T prefix . command-prompt "move-window -t '%%'"
# bind-key -T prefix / command-prompt -k -p key "list-keys -1N \"%%%\""
# bind-key -T prefix D choose-client -Z
# bind-key -T prefix L switch-client -l
# bind-key -T prefix o select-pane -t :.+
# bind-key -T prefix q display-panes
# bind-key -T prefix r refresh-client
# bind-key -T prefix t clock-mode
# bind-key -T prefix \~ show-messages
# bind-key -r -T prefix DC refresh-client -c
################################################################################
# Plugins #
################################################################################
# Directory for saving tmux resurrect files.
set -g @resurrect-dir '~/.local/var/tmux/resurrect'
run '~/submodules/tmux/tmux-resurrect/*.tmux'
# Only enable tmux-continuum for the default socket.
%if "#{==:#{b:socket_path},default}"
run '~/submodules/tmux/tmux-continuum/*.tmux'
%endif
# Rebind restore key to confirm before, since restoring can be destructive.
bind 'C-r' confirm-before -p 'Restore?' 'run ~/submodules/tmux/tmux-resurrect/scripts/restore.sh'
set -g @colors-solarized 'dark'
run '~/submodules/tmux/tmux-colors-solarized/*.tmux'
set -g @prefix_highlight_fg 'colour235' # default is 'colour231'
set -g @prefix_highlight_bg 'yellow' # default is 'colour04'
set -g @prefix_highlight_copy_prompt 'Copy'
set -g @prefix_highlight_show_copy_mode 'off'
set -g @prefix_highlight_copy_mode_attr 'fg=colour235,bg=yellow,bold' # default is 'fg=default,bg=yellow'
set -g @prefix_highlight_show_sync_mode 'on'
set -g @prefix_highlight_sync_mode_attr 'fg=colour235,bg=yellow,bold' # default is 'fg=default,bg=yellow'
run '~/submodules/tmux/tmux-prefix-highlight/*.tmux'
# As of 2020-08-12, I stopped using tmux-open, since it's straightforward to
# implement it and I need more customization.
# # tmux-open settings: in tmux copy mode, press o to open with xdg-open, Shift-o
# # to open in editor, s to search in google.
# set -g @open 'o'
# set -g @open-editor 'S-o'
# set -g @open-opener-command 'sensible-open'
# set -g @open-s 'https://www.google.com/search?q='
# run '~/submodules/tmux/tmux-open/*.tmux'
# set -g @plugin 'jbnicolai/tmux-fpp'
# set -g @fpp-key 'e'
# As of 2018-12-07 I don't see any benefit in using tmux-sensible with my
# current settings- I reviewed the plugin code and copied anything that wasn't
# already set.
# set -g @plugin 'tmux-plugins/tmux-sensible'
# tmux-yank doesn't work for me, so I'm passing the keys to zsh and doing the
# copy there. See also:
# https://github.com/tmux-plugins/tmux-yank/issues/48#issuecomment-283030691
# set -g @plugin 'tmux-plugins/tmux-yank'
# set -g @plugin 'nhdaly/tmux-scroll-copy-mode'
# This plugin malfunctions so it is disabled.
# set -g @plugin 'tmux-plugins/tmux-copycat'