-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.tmux.conf
125 lines (104 loc) · 5.76 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
# remap prefix to Control + f
set -g prefix C-f
bind C-f send-prefix
unbind C-b
# Enable mouse mode
set -g mouse on
# Use vi keybindings in copy mode
setw -g mode-keys vi
# Using iTerm the following works
# To make this universal on all operating systems I guess I would something like
# https://github.com/tmux-plugins/tmux-yank or add some if condition
bind-key h copy-mode
bind-key -T copy-mode-vi v send-keys -X begin-selection
bind-key -T copy-mode-vi y send-keys -X copy-selection-and-cancel
# Allow to quickly edit and reload the tmux config
bind-key r source-file ~/.tmux.conf \; display-message "~/.tmux.conf reloaded"
bind-key M split-window -h "vim ~/.tmux.conf"
# Start windows and panes at 1, not 0
set -g base-index 1
setw -g pane-base-index 1
# increase the repeat-time so it is a bit easier with resizing panes
set-option -g repeat-time 1000
# don't hold up esc-key press => set so switching to normal mode in vim is faster again
set -s escape-time 0
# PANE MGMT
is_vim="ps -o state= -o comm= -t '#{pane_tty}' | grep -iqE '^[^TXZ ]+ +(\\S+\\/)?g?(view|n?vim?x?)(diff)?$'"
bind-key -n C-w "switch-client -T paneMgmt; display-panes -N -d 0"
# seamless pane navigation with vim splits
bind-key -n -T paneMgmt 'h' if-shell "$is_vim" 'send-keys C-h' 'select-pane -L'
bind-key -n -T paneMgmt 'j' if-shell "$is_vim" 'send-keys C-j' 'select-pane -D'
bind-key -n -T paneMgmt 'k' if-shell "$is_vim" 'send-keys C-k' 'select-pane -U'
bind-key -n -T paneMgmt 'l' if-shell "$is_vim" 'send-keys C-l' 'select-pane -R'
bind-key -n -T paneMgmt 'w' 'send-keys C-w' # in case we ever need to use the in vim command
# pane spawning and killing
bind-key -n -r -T paneMgmt 's' 'split-window -v -c "#{pane_current_path}"'
bind-key -n -r -T paneMgmt 'v' 'split-window -h -c "#{pane_current_path}"'
bind-key -n -r -T paneMgmt 'q' 'kill-pane'
bind-key -n -r -T paneMgmt ']' 'swap-pane -D'
bind-key -n -r -T paneMgmt '[' 'swap-pane -U'
# pane sizing
bind-key -n -r -T paneMgmt 'H' 'resize-pane -L 5'
bind-key -n -r -T paneMgmt 'J' 'resize-pane -D 5'
bind-key -n -r -T paneMgmt 'K' 'resize-pane -U 5'
bind-key -n -r -T paneMgmt 'L' 'resize-pane -R 5'
bind-key -n -r -T paneMgmt 'z' 'resize-pane -Z'
# pane layout
bind-key -n -T paneMgmt '=' 'select-layout even-vertical'
bind-key -n -T paneMgmt '\' 'select-layout even-horizontal'
bind-key -n -T paneMgmt 'u' 'select-layout -o'
bind-key -n -r -T paneMgmt 'Space' 'next-layout'
bind-key -n -r -T paneMgmt 'o' 'rotate-window -U'
# moving pane to another session
bind-key -n -T paneMgmt 'm' command-prompt -p "send pane to:" "join-pane -t '%%'"
bind-key -n -T paneMgmt 'n' 'break-pane'
# bind-key -n -T paneMgmt '}' "join-pane -t '%%'"
#TODO figure out why next_window is empty in this bind-key -n -T paneMgmt '}' run-shell "bash -c current_window=$(echo '#I') && next_window=$((current_window+1)) && tmux display-message -p $next_window"
#TODO not sure if we need this bind-key -n -T paneMgmt 'f' command-prompt -p "join pane from:" "join-pane -s '%%'"
# SESSIONS MGMT
bind-key -n C-s switch-client -T sessionMgmt
bind-key -n -T sessionMgmt 'l' 'switch-client -n'
bind-key -n -T sessionMgmt 'h' 'switch-client -p'
bind-key -n -T sessionMgmt 'q' confirm-before -p "kill-session #S? (y/n)" "run-shell 'tmux switch-client -l \; tmux kill-session -t "#S"'"
bind-key -n -T sessionMgmt 'n' command-prompt -p "New session name:" "new-session -s %1"
bind-key -n -T sessionMgmt 'r' command-prompt -I "#S" "rename-session -- '%%'"
bind-key -n -T sessionMgmt 's' 'choose-tree -Zs'
bind-key -n -T sessionMgmt 'p' 'switch-client -l' # go to last session
# WINDOWS MGMT
bind-key -n C-a switch-client -T windowMgmt
bind-key -n -r -T windowMgmt 'l' 'next-window'
bind-key -n -r -T windowMgmt 'h' 'previous-window'
bind-key -n -r -T windowMgmt ']' 'swap-window -t:+1; next-window'
bind-key -n -r -T windowMgmt '[' 'swap-window -t:-1; previous-window'
bind-key -n -T windowMgmt 'r' 'command-prompt -I "" "rename-window -- '%%'"'
bind-key -n -T windowMgmt 'n' 'new-window -c "#{pane_current_path}"' # open new window in the same directory
bind-key -n -T windowMgmt 'q' confirm-before -p "kill-window #W? (y/n)" kill-window
bind-key -n -T windowMgmt 'j' choose-window 'move-window -s "%%"' # move the selected window into the current session
bind-key -n -T windowMgmt 'm' choose-session 'move-window -t "%%"; switch -t "%%"' # move current window into the session about to be selected
# As we have binded C-a from jumping to the beginning of a line to tmux window-management, allow to jump to the beginning by pressing a again
bind-key -n -T windowMgmt 'a' send-keys C-a
# display current keytable in bottom left
set -g status-left "#{s/root//:client_key_table} "
# enable focus events. This is required for the git-gutter vim-plugin (https://github.com/airblade/vim-gitgutter/blob/master/README.mkd#vim-gitgutter section constraints)
set -g focus-events on
# use zsh as my default shell
set-option -g default-shell /bin/zsh
# change color of active window
setw -g window-status-current-style 'bg=cyan'
set -g status-interval 5 # set update interval of status bar to 5
set -g status-justify centre # center window list
# PLUGINS (dont forget to `git clone https://github.com/tmux-plugins/tpm ~/.tmux/plugins/tpm` on new installations)
# Initialize TMUX plugin manager (keep this line at the very bottom of tmux.conf)
run '~/.tmux/plugins/tpm/tpm'
set -g @plugin 'tmux-plugins/tpm'
# automatically persist sessions on reboot
set -g @plugin 'tmux-plugins/tmux-resurrect'
set -g @plugin 'tmux-plugins/tmux-continuum'
set -g @resurrect-strategy-vim 'session'
set -g @resurrect-strategy-nvim 'session'
set -g @resurrect-capture-pane-contents 'on'
set -g @continuum-restore 'on'
# Automatically go into last session if being called by tmux resurrect
set -g @resurrect-processes '"vim->vim +SLoad"'
# Display session name in right corner
set -g status-right ' #S '