-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy path.tmux.conf
222 lines (170 loc) · 6.31 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
# PastLeo's ~/.tmux.conf
# for tmux -V >= 2.9
# -----------------------------
# Global settings
# -----------------------------
# scrollback buffer n lines
set -g history-limit 5000
# listen for activity on all windows
set -g bell-action any
# start window indexing at 1 window so the <prefix> 1 is easier to reach
set -g base-index 1
# enable 24bit true color for vim termguicolors according to ~/.shrc.once
if-shell '[ -n "$TERM_RGB" ]' \
"set -ag terminal-overrides ',xterm-256color:RGB'"
# xterm-style function key sequences
setw -g xterm-keys on
# control automatic window renaming
setw -g automatic-rename off
# enable wm window titles
set -g set-titles on
# remove <esc> key press delay
set -sg escape-time 0
SET_DEFAULT_SHELL='tmux set-option -g default-shell $TMUX_DEFAULT_SHELL'
if-shell '[ -n "$TMUX_DEFAULT_SHELL" ]' \
"run-shell '${SET_DEFAULT_SHELL}'"
# -----------------------------
# Key bindings
# -----------------------------
# set <prefix> key to C-a
set-option -g prefix C-a
# use C-a again to send ctrl-a to inner session
bind-key C-a send-prefix
# detach session, keeping the program running
bind-key d detach
# Create window
bind-key -r n new-window
bind-key -r C-n new-window
bind-key -r N new-window -c '#{pane_current_path}'
# split windows (create pane)
bind-key _ split-window -v -c '#{pane_current_path}'
bind-key | split-window -h -c '#{pane_current_path}'
# kill current pane when the inner process is unable to exit for whatever reason
bind-key q confirm-before kill-pane
# <prefix> or Ctrl- or <prefix> Ctrl-
# k --- previous pane
# h l --- previous window / next window
# j --- next pane
# navigate windows
unbind-key l
bind-key h select-window -t :-
bind-key C-h select-window -t :-
bind-key -n C-h select-window -t :-
bind-key l select-window -t :+
bind-key C-l select-window -t :+
bind-key -n C-l select-window -t :+
# navigate panes
bind-key j select-pane -t :.-
bind-key C-j select-pane -t :.-
bind-key -n C-j select-pane -t :.-
bind-key k select-pane -t :.+
bind-key C-k select-pane -t :.+
bind-key -n C-k select-pane -t :.+
# rename title
bind-key , command-prompt "rename-window %%"
# move the split line (resize pane)
# <prefix> shift-
# k --- up
# h l --- left / right
# j --- down
bind-key -r H resize-pane -L 3
bind-key -r L resize-pane -R 3
bind-key -r K resize-pane -U 1
bind-key -r J resize-pane -D 1
# move (swap) panes and windows
# <prefix> alt-
# k --- move pane next
# h l --- move window left / move window right
# j --- move pane previous
bind-key -r M-h swap-window -t :- \; select-window -t :-
bind-key -r M-j swap-pane -D
bind-key -r M-k swap-pane -U
bind-key -r M-l swap-window -t :+ \; select-window -t :+
# change window pane layouts
bind-key -r M-f next-layout
# zoom a pane between full-screen and pane-size
bind-key -r z resize-pane -Z
bind-key -n C-z resize-pane -Z
# vi-style controls for copy mode
setw -g mode-keys vi
# C-v directly to enter vi-mode
bind-key [ copy-mode \; set mouse off
bind-key v copy-mode \; set mouse off
bind-key -n C-v copy-mode \; set mouse off
# select and copy like vi in vi-mode
bind-key -T copy-mode-vi v send -X begin-selection
bind-key -T copy-mode-vi y send -X copy-selection
# if encounter incompatible with send-keys/send -X, use lagacy setting:
# bind-key -t vi-copy 'v' begin-selection
# bind-key -t vi-copy 'y' copy-selection
# C-] directly to paste
bind-key ] paste-buffer
bind-key p paste-buffer
bind-key -n C-] paste-buffer
# enable navigation in vi mode
bind-key -T copy-mode-vi C-h select-window -t :-
bind-key -T copy-mode-vi C-l select-window -t :+
bind-key -T copy-mode-vi C-j select-pane -t :.-
bind-key -T copy-mode-vi C-k select-pane -t :.+
set -g mouse on
bind-key m set -g mouse on \; display "Mouse mode on"
bind-key M set -g mouse off \; display "Mouse mode off"
bind-key -T copy-mode-vi C-k send-keys -X cancel \; set mouse on
bind-key -T copy-mode-vi q send-keys -X cancel \; set mouse on
## Other useful commands
# open a man page in new pane, using q to leave
bind-key / command-prompt -p 'man ' "split-window -h 'exec man %%'"
bind-key r command-prompt -p 'Command >> ' "split-window -c '#{pane_current_path}' -h '%%; echo \"Press enter to continue.\"; read;'"
# reload settings
bind-key R source-file ~/.tmux.conf
# Prevent terminal freezing by C-s
bind-key -n C-s display 'Terminal freezing by C-s prevented'
# -----------------------------
# Statusbar settings
# -----------------------------
# use vi-style key bindings in the status line
set -g status-keys vi
# amount of time for which status line messages and other indicators
# are displayed. time is in milliseconds.
set -g display-time 2000
# default statusbar colors
set -g status-style fg=white,bg=default
# default window title colors
set -g window-status-style fg=white,bg=default,dim
# active window title colors
set -g window-status-current-style fg=cyan,bg=default,bright,underscore
# command/message line colors
set -g message-style fg=white,bg=black,bright
# what to be displayed on the right status
set -g status-interval 1
set -g status-right ' } %Y-%m-%d %H:%M:%S'
set -g status-right-length 60
# what to be displayed on the left status
set -g status-left-length 30
set-option -g status-left "#[fg=green]#(echo $USER)#[default].#[fg=blue]#h#[default] { "
# -----------------------------
# https://github.com/tmux-plugins/tmux-yank
# -----------------------------
if-shell '[ "$(uname)" == "Darwin" ] || [ "$DISPLAY" ]' {
if-shell '[ -e ~/.local/tmux-yank/yank.tmux ]' {
run-shell ~/.local/tmux-yank/yank.tmux
} {
display "tmux-yank not installed, run:"
display " mkdir -p ~/.local"
display " git clone https://github.com/tmux-plugins/tmux-yank ~/.local/tmux-yank"
display "visit for more info: https://github.com/tmux-plugins/tmux-yank#requirements"
}
}
# -----------------------------
# Platform fix
# -----------------------------
# keep PATH for subprocess
run-shell 'tmux setenv -g TMUX_PATH $PATH'
# -----------------------------
# Multiple sessions detection
# -----------------------------
MULTIPLE_SESSION_WARN='display-message -p "=== WARN ===" ; \
display-message -p " Multiple tmux sessions detected," ; \
display-message -p " environment variables are from the first session" ;'
CHECK_MULTIPLE_SESSION="if-shell -b '[ $(tmux list-sessions | wc -l) -gt 1 ]' '${MULTIPLE_SESSION_WARN}'"
set-hook -g session-created ${CHECK_MULTIPLE_SESSION}