-
Notifications
You must be signed in to change notification settings - Fork 0
/
.tmux.conf
323 lines (270 loc) · 14 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
# [tmux\(1\) \- Linux manual page]( http://man7.org/linux/man-pages/man1/tmux.1.html )
# reset keybind
# { echo 'unbind-key -a'; tmux -f /dev/null -L temp start-server \; list-keys; } > .tmux.reset.conf
source-file "$HOME/.tmux.reset.conf"
# set = set-option
# setw = set-window-option
# bind = bind-key
run-shell "tmux setenv -g TMUX_VERSION $(tmux -V | perl -pe 's/[^\\d]*(\\d+\\.\\d+|\\d+)[^\\d]*/(0+$1)/ge;')"
# NOTE: for tmux version compatibility
# if-shell -b '[[ "$(echo "$TMUX_VERSION < 1.9" | bc)" -eq 1 ]]' \
# "xxx; \
# yyy"
# NOTE: key settings
# []: default key
# -r: like a vim submode
# -a: the new window is inserted at the next index up from the specified target-window, moving win‐ dows up if necessary, otherwise target-window is the new window location.
# NOTE: t: tab, n: next, p: prev
bind t new-window -a -c '#{pane_current_path}' # tab [c]
bind c-t new-window -a -c '#{pane_current_path}' # tab [c]
bind -n † new-window -a -c '#{pane_current_path}' # tab [c] # alt+t
bind -n M-t new-window -a -c '#{pane_current_path}' # tab [c] # alt+t
bind n next-window
bind -r right next-window
bind c-n next-window
bind -n ˜ next-window # alt+n
bind -n M-n next-window # alt+n
bind p previous-window
bind -r left previous-window
bind c-p previous-window
bind -n π previous-window # alt+p
bind -n M-p previous-window # alt+p
# NOTE: s,v: from vim setting
# NOTE: - is for resize
bind = split-window -v -c '#{pane_current_path}'
bind - split-window -v -c '#{pane_current_path}' # for us key mapping
bind _ split-window -v -c '#{pane_current_path}' # for us key mapping
bind -n – split-window -v -c '#{pane_current_path}' # alt+-
bind -n M-- split-window -v -c '#{pane_current_path}' # alt+-
bind s split-window -v -c '#{pane_current_path}'
bind v split-window -h -c '#{pane_current_path}'
bind c-s split-window -v -c '#{pane_current_path}'
bind c-v split-window -h -c '#{pane_current_path}'
# [terminal \- Tmux: how do I bind to C\-\- \(control\-minus\)? \- Unix & Linux Stack Exchange]( https://unix.stackexchange.com/questions/158278/tmux-how-do-i-bind-to-c-control-minus )
bind | split-window -h -c '#{pane_current_path}'
bind c-\\ split-window -h -c '#{pane_current_path}' # for us key mapping
bind -n M-\\ split-window -h -c '#{pane_current_path}'
bind -n « split-window -h -c '#{pane_current_path}'
bind j select-pane -D
bind k select-pane -U
bind h select-pane -L
bind l select-pane -R
bind c-j select-pane -D
bind c-k select-pane -U
bind c-h select-pane -L
bind c-l select-pane -R
# w -> select window
bind -r < resize-pane -L 1
bind -r > resize-pane -R 1
# bind -r - resize-pane -D 1
# bind -r + resize-pane -U 1
bind -n S-Up send-keys Pageup
bind -n S-down send-keys Pagedown
bind -r H resize-pane -L 5
bind -r J resize-pane -D 5
bind -r K resize-pane -U 5
bind -r L resize-pane -R 5
# find window
# bind f choose-window
# select window by number
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
# NOTE: help
# [What is the command for inline help in tmux? \- Super User]( https://superuser.com/questions/737075/what-is-the-command-for-inline-help-in-tmux )
# <C-b>+? or :list-commands
# switch session
bind c choose-session
bind -r tab switch-client -n
bind -r S-tab switch-client -r
# move window tab
bind -r S-left swap-window -t -1
bind -r S-down last-window
bind -r S-up choose-window
bind -r S-right swap-window -t +1
# bind g display-pane
# bind C-g display-pane
# bind b select-pane -t :.+
# bind C-b select-pane -t :.+
# bind B select-pane -t :.-
# bind -n M-left select-pane -L
# bind -n M-down select-pane -D
# bind -n M-up select-pane -U
# bind -n M-right select-pane -R
# NOTE: M: alt
bind -n M-left previous-window
bind -n M-down last-window
bind -n M-up choose-window
bind -n M-right next-window
bind -n M-[ select-pane -L # NOTE: M-[
bind -n M-] select-pane -R # NOTE: M-]
bind -n “ select-pane -L # NOTE: M-[
bind -n ‘ select-pane -R # NOTE: M-]
bind -n ˙ select-pane -L # NOTE: alt+h
bind -n ∆ select-pane -D # NOTE: alt+j
bind -n ˚ select-pane -U # NOTE: alt+k
bind -n ¬ select-pane -R # NOTE: alt+l
bind -n M-h select-pane -L # NOTE: alt+h
bind -n M-j select-pane -D # NOTE: alt+j
bind -n M-k select-pane -U # NOTE: alt+k
bind -n M-l select-pane -R # NOTE: alt+l
# bind v copy-mode
bind b copy-mode
bind C-b copy-mode
bind B copy-mode
bind Escape copy-mode
bind -n C-Up copy-mode
bind -n C-Down copy-mode
bind : command-prompt
bind S confirm-before 'kill-session'
bind X confirm-before 'kill-session'
bind q confirm-before 'kill-session'
bind C-S confirm-before 'kill-session'
bind C-X confirm-before 'kill-session'
bind C-q confirm-before 'kill-session'
# -g: global session
setw -g mode-keys vi
set -g repeat-time 400 # wait time[ms] like vim submode
set -g display-time 1000 # [msec]
set -g status-interval 1 # [sec]
set -sg escape-time 0 # [msec]
# NOTE: this is scorll-buffer size
# FYI: [Unlimited history in tmux \- Unix & Linux Stack Exchange]( https://unix.stackexchange.com/questions/43414/unlimited-history-in-tmux )
# WARN: This will pre-allocate that many lines (and hence memory) for all windows, which is going to cripple your machine the more history is stored over time.
set -g history-limit 10000
# update the TERM variable of terminal emulator when creating a new session or attaching a existing session
set -g update-environment 'DISPLAY SSH_ASKPASS SSH_AGENT_PID SSH_CONNECTION WINDOWID XAUTHORITY TERM'
# if condition true-script false-script
if "[[ $TERM_PROGRAM == iTerm.app ]]" 'set-option -g default-terminal "screen-256color"' 'set-option -g default-terminal "tmux-256color"'
set-option -ga terminal-overrides ",$TERM:Tc"
# status line
set -g status-position bottom # maybe default
set -g status-left-length 40
set -g status-right-length 80
# NOTE: at Mac OS X or not
# #(sh command) is executed at tmux server environment (therefore, you cannot detect current current tmux session is attached via ssh session or not)
# WARN: don't use wide char at status-line on Windows Terminal #([ "$(uname)" = "Linux" ] && printf "🍺")
set -g status-left "#{?client_prefix,#[reverse],}#([ \"$(uname)\" = \"Darwin\" ] && printf \"🍎\")[#{window_index}]#{session_name} "
# set -g status-right "M<#{pane_mode}> S[#{window_index}] W(#{window_index}/#{session_windows}) P{#{pane_index}/#{window_panes}} #(pwd | sed 's:^$HOME:~:')"
set -g status-style fg="colour047",bg="colour234"
set -g status-left-style fg="colour039",bg="colour234"
set -g status-right-style fg="colour201",bg="colour233"
setw -g window-status-format "#{window_index}:#{window_name}"
setw -g window-status-current-format "#{window_index}:#{window_name}{#{pane_index}/#{window_panes}}"
setw -g window-status-current-style fg="colour234",bg="colour047"
setw -g xterm-keys on
set -g message-style fg="colour238",bg="colour190"
set -g window-style fg="colour244",bg="colour237"
set -g window-active-style fg="colour255",bg="terminal"
set -g pane-border-style fg="default",bg="default"
set -g pane-active-border-style fg="default",bg="default"
# color setting of upper right prompt at copy-mode
set -g mode-style fg="colour238",bg="colour190"
# Please set colour59 instead of #000032 for 256-color
# save current pane background and load the setting
set-hook -g pane-mode-changed "if -F \"#{m/r:(copy|view)-mode,#{pane_mode}}\" \"set -pF @_pane_bg '#{pane_bg}'; select-pane -P 'bg=#000032'\" \"select-pane -P 'bg=#{@_pane_bg}'\";"
bind r display-message "[log] start reload config!" \; source-file ~/.tmux.conf \; display-message "[log] end reload config!"
# auto reorder tab(window) id
set-option -g renumber-windows on
# enable tab(window) switch by mouse drag
bind-key -n MouseDrag1Status swap-window -d -t=
set -g mouse on
# rename window to current path
set -g automatic-rename on
set -g automatic-rename-format '#{b:pane_current_path}'
set -g set-titles on
set -g set-titles-string "#{session_name}"
# NOTE: default is ' -_@'
set -g word-separators ' []{}|#&*()+=:;<>,?'
# search setting
bind-key / copy-mode \; send-key ?
bind-key f copy-mode \; send-key ?
bind-key c-f copy-mode \; send-key ?
# copy-pipe: clear selection, keep scroll position
# copy-pipe-no-clear: keep selection, keep scroll position
# copy-pipe-and-cancel: clear selection, clear scroll position
# Linux with xsel
# enable v -> v for copy
if "which xsel" "bind-key -T copy-mode-vi v send-keys -X copy-pipe 'xsel -bi' \\; send-keys -X begin-selection"
if "which xsel" "bind-key -T copy-mode-vi V send-keys -X select-line"
# if "which xsel" "bind-key -T copy-mode-vi C-v send-keys -X rectangle-toggle"
if "which xsel" "bind-key -T copy-mode-vi y send-keys -X copy-pipe 'xsel -bi'"
if "which xsel" "bind-key -T copy-mode-vi Enter send-keys -X copy-pipe 'xsel -bi'"
if "which xsel" "bind-key -T copy-mode-vi Y send-keys -X copy-line"
if "which xsel" "bind-key -T copy-mode-vi MouseDragEnd1Pane send-keys -X copy-pipe 'xsel -bi'"
# copy current line
if "which xsel" "bind-key y copy-mode \\; send-keys -X select-line \\; run-shell 'sleep 0.05' \\; send-keys -X copy-pipe 'xsel -bi'"
if "which xsel" "bind-key C-y copy-mode \\; send-keys -X select-line \\; run-shell 'sleep 0.05' \\; send-keys -X copy-pipe 'xsel -bi'"
if "which xsel && which trim-tmux-line" "bind-key y copy-mode \\; send-keys -X select-line \\; run-shell 'sleep 0.05' \\; send-keys -X copy-pipe 'trim-tmux-line | xsel -bi'"
if "which xsel && which trim-tmux-line" "bind-key C-y copy-mode \\; send-keys -X select-line \\; run-shell 'sleep 0.05' \\; send-keys -X copy-pipe 'trim-tmux-line | xsel -bi'"
# Mac OS X
# Ctrl+b [ -> v -> v or y or Enter
# with mouse -> with opt key
# enable v -> v for copy
if "which pbcopy" "bind-key -T copy-mode-vi v send-keys -X copy-pipe 'xsel -bi' \\; send-keys -X begin-selection"
if "which pbcopy" "bind-key -T copy-mode-vi V send-keys -X select-line"
# if "which pbcopy" "bind-key -T copy-mode-vi C-v send-keys -X rectangle-toggle"
if "which pbcopy" "bind-key -T copy-mode-vi y send-keys -X copy-pipe 'pbcopy'"
if "which pbcopy" "bind-key -T copy-mode-vi Enter send-keys -X copy-pipe 'pbcopy'"
if "which pbcopy" "bind-key -T copy-mode-vi Y send-keys -X copy-line"
if "which pbcopy" "bind-key -T copy-mode-vi MouseDragEnd1Pane send-keys -X copy-pipe 'pbcopy'"
if "which pbcopy" "bind-key -T copy-mode-vi MouseDragEnd1Pane send-keys -X copy-pipe 'pbcopy'"
# unbind -T copy-mode-vi MouseDragEnd1Pane
# copy current line
if "which pbcopy" "bind-key y copy-mode \\; send-keys -X select-line \\; run-shell 'sleep 0.05' \\; send-keys -X copy-pipe 'pbcopy'"
if "which pbcopy" "bind-key C-y copy-mode \\; send-keys -X select-line \\; run-shell 'sleep 0.05' \\; send-keys -X copy-pipe 'pbcopy'"
if "which pbcopy && which trim-tmux-line" "bind-key y copy-mode \\; send-keys -X select-line \\; run-shell 'sleep 0.05' \\; send-keys -X copy-pipe 'trim-tmux-line | pbcopy'"
if "which pbcopy && which trim-tmux-line" "bind-key C-y copy-mode \\; send-keys -X select-line \\; run-shell 'sleep 0.05' \\; send-keys -X copy-pipe 'trim-tmux-line | pbcopy'"
bind-key -T copy-mode-vi i send-keys -X select-word
# bind-key -T copy-mode-vi iw select-word
# Double Click Select & Copy (Word)
# FYI: [Can I use double click to select and copy in tmux? \- Stack Overflow]( https://stackoverflow.com/questions/31404140/can-i-use-double-click-to-select-and-copy-in-tmux )
# mouse click with option key -> The clicked area is processed by the terminal itself.
# NOTE: sleep for visualization
# NOTE: this copy-mode is command for use select-word command
if "which xsel" "bind-key -n DoubleClick1Pane copy-mode \\; send-keys -X select-word \\; run-shell 'sleep 0.05' \\; send-keys -X copy-pipe-and-cancel 'xsel -bi'"
if "which pbcopy" "bind-key -n DoubleClick1Pane copy-mode \\; send-keys -X select-word \\; run-shell 'sleep 0.05' \\; send-keys -X copy-pipe-and-cancel 'pbcopy'"
# NOTE: copy-mode-vi is also enabled at scrolling
if "which xsel" "bind-key -T copy-mode-vi DoubleClick1Pane send-keys -X select-word \\; run-shell 'sleep 0.05' \\; send-keys -X copy-pipe-and-cancel 'xsel -bi'"
if "which pbcopy" "bind-key -T copy-mode-vi DoubleClick1Pane send-keys -X select-word \\; run-shell 'sleep 0.05' \\; send-keys -X copy-pipe-and-cancel 'pbcopy'"
# if "which xsel" "bind-key C-o run 'tmux set-buffer -- \"$(xsel -bo)\"; tmux paste-buffer -p'"
if "which xclip" "bind-key C-o run 'tmux set-buffer -- \"$(xclip -o -sel clip)\"; tmux paste-buffer -p'"
if "which pbcopy" "bind-key C-o run 'tmux set-buffer -- \"$(pbpaste)\"; tmux paste-buffer -p'"
# for ctrl + shift + key
# if "which xsel" "bind-key -n '' run 'tmux set-buffer -- \"$(xsel -bo)\"; tmux paste-buffer -p'"
if "which xclip" "bind-key -n '' run 'tmux set-buffer -- \"$(xclip -sel clip)\"; tmux paste-buffer -p'"
if "which pbcopy" "bind-key -n '' run 'tmux set-buffer -- \"$(pbpaste)\"; tmux paste-buffer -p'"
# Install: paste + I
### tmux plugins
set -g @plugin 'tmux-plugins/tpm'
# Copy: prefix + space
# Paste: prefix + ]
set -g @plugin 'fcsonline/tmux-thumbs'
set -g @thumbs-command 'echo -n {} | { type pbcopy >/dev/null 2>&1 && pbcopy; } || { type xsel >/dev/null 2>&1 && xsel -bi; }'
# prefix + Ctrl-s - save
# prefix + Ctrl-r - restore
set -g @plugin 'tmux-plugins/tmux-resurrect'
set -g @plugin 'tmux-plugins/tmux-continuum'
unbind C-r # disable for an accident
set -g @continuum-restore 'on' # restore session info at tmux start
set -g @continuum-save-interval '5' # 5min
# prefix + space: enter in thumbs mode
set -g @plugin 'fcsonline/tmux-thumbs'
set -g @plugin 'schasse/tmux-jump'
set -g @jump-key 'g'
# prefix + tab
set -g @plugin 'laktak/extrakto'
set -g @extrakto_copy_key "tab" # use tab to copy to clipboard
set -g @extrakto_insert_key "enter" # use enter to insert selection
# prefix + ctrl-f - simple file search
# prefix + ctrl-g - jumping over git status files (best used after git status command)
# set -g @plugin 'tmux-plugins/tmux-copycat'
# Initialize TMUX plugin manager (keep this line at the very bottom of tmux.conf)
run '~/.tmux/plugins/tpm/tpm'