-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path.tmux.conf
193 lines (166 loc) · 11.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
# to reload its prefix + : then source-file ~/.tmux.conf
# clearly its not right to set both of these - but i wonder of the effect when using tmux in a screen session
# see here for a little more info https://github.com/tmux/tmux/issues/353#issuecomment-203038518
# however something needs 256 colour mode (oddly i think something to do with the zsh theme or its powerline requirement)
#set -g default-terminal "xterm"
set -g default-terminal "screen-256color"
# this because checkhealth on neovim said to do it to enable termguicolors, didn't work though
set-option -sa terminal-overrides ',screen-256color:RGB'
set -g status-bg black
set -g status-fg white
set -g pane-border-style fg=colour235 #base02
set -g pane-active-border-style fg=colour240 #base01
setw -g monitor-activity on
set -g visual-activity on
# these status declarations only apply to my non-maglev statusline, i can see them all when maglev isn't active (and curling to get my ip address seems a little off to me!)
set -g status-left-length 70
set -g status-left "#[fg=green] #h :: #[fg=brightblue]#(curl icanhazip.com) ::#[fg=yellow]#(ifconfig en0 | grep 'inet ' | awk '{print \"en0 \" $2}') #(ifconfig en1 | grep 'inet ' | awk '{print \"en1 \" $2}') #[fg=red]#(ifconfig tun0 | grep 'inet ' | awk '{print \"vpn \" $2}') "
set -g status-right-length 60
set -g status-right "#[fg=blue]#S #I:#P #[fg=yellow]:: %d %b %Y #[fg=green]::%l:%M %p"
set -g mouse on
# remap prefix to Control + a, ctrl+b is not only terrible to type, it now interferes with copy-mode-vi page back
set -g prefix C-a
unbind C-b
bind C-a send-prefix
#now set vi mode and standard vi keys
setw -g mode-keys vi
#change the default keybinds to make vim-like. As explained in the man page, the default keys to enter and exit copy mode are [ .and ] respectively. I reset those
unbind [
bind Escape copy-mode
#changing to upper case because it interferes with previous window instruction
unbind P
bind P paste-buffer
# see the tmux-yank setting below? set -g @yank_action 'copy-pipe'. that will stop you exiting copy mode and scrolling to the end of the scrollback buffer when you yank selected text
# BUTTTT...the mouse behaviour still exists and loses scrollback position, to do the same in mouse mode, we need this: https://github.com/tmux/tmux/issues/140
unbind-key -T copy-mode-vi MouseDragEnd1Pane
# and we need copy-selection -x below (which previously read bind -T copy-mode-vi y send -X copy-selection-and-cancel ).
# (Good luck persisting these settings as tmux syntax breakingly-changes quite a lot, see issue140 there for the latest...)
# while in copy mode, be vim like
# a good example of how to copy and paste: https://leanside.com/2014/01/copy-paste-in-tmux/
bind -T copy-mode-vi v send -X begin-selection
#bind -T copy-mode-vi y send -X copy-selection-and-cancel - lets try no to lose scrollback postition
bind -T copy-mode-vi y send -X copy-selection -x
bind -T copy-mode-vi Y send -X copy-end-of-line
#changes between linewise and columnwise selection
bind -T copy-mode-vi V send -X rectangle-toggle
#next step is to connect that up to osx's paste buffer
#see here: http://unix.stackexchange.com/questions/15715/getting-tmux-to-copy-a-buffer-to-the-clipboard
# also here: https://github.com/ChrisJohnsen/tmux-MacOSX-pasteboard
# you must brew install reattach-to-user-namespace for this next bit to not crash out tmux
set-option -g default-command "reattach-to-user-namespace -l zsh #or bash"...
bind C-c run "tmux save-buffer - | reattach-to-user-namespace pbcopy"
bind C-v run "reattach-to-user-namespace pbpaste | tmux load-buffer - && tmux paste-buffer"
#To copy the buffer from tmux (you should have already copied something using tmux)
# into the Mac pasteboard, use <tmux-key> Control-c. It will now be available for Command-v or pbpaste
#To paste something from the Mac pasteboard, use <tmux-key> Control-v.
#to make new panes start in current dir
bind c new-window -c "#{pane_current_path}"
bind % split-window -h -c "#{pane_current_path}"
bind '"' split-window -v -c "#{pane_current_path}"
#change orientation of two panes
# attempts to flip the orientation of the current pane with the pane before it (in the ordering) -- http://stackoverflow.com/a/27450841/3536094
# this doesn't work well but one press works ok, the problem this solves is that PREFIX + space moves ALL panes
bind C-q move-pane -t '.-'
bind C-w move-pane -h -t '.-'
# Tmux helpfully changes window names to match current app - filename, this is often very useful UNTIL we manually change a window's name, once we've done that we want it to stick!
# according to https://stackoverflow.com/a/34004541/3536094, this should do precicely that (see comments e.g.: Drasil), however this command does not display in :list-commands
set-option -g allow-rename off
#start of 'so-called maglev settings' - these are in the maglev readme, BUT its unclear if they
# are necessary for operation or not, i ran without them for ages without maglev issue
# Start windows and panes at 1, not 0
set -g base-index 1
set -g pane-base-index 1
set-option -g status-position top
set-option -g repeat-time 0
# Removes ESC delay - see this though: https://github.com/tmux/tmux/issues/353#issuecomment-294570322
set -sg escape-time 0
# end of 'so-called maglev settings'
# List of plugins https://github.com/tmux-plugins/
# these are actually a straight copy/paste off the maglev readme, but are all very sensible. only some are maglev dependencies
set -g @tpm_plugins ' \
caiogondim/maglev \
tmux-plugins/tpm \
tmux-plugins/tmux-sensible \
tmux-plugins/tmux-resurrect \
tmux-plugins/tmux-yank \
tmux-plugins/tmux-pain-control \
tmux-plugins/tmux-copycat \
tmux-plugins/tmux-open \
tmux-plugins/tmux-continuum \
tmux-plugins/tmux-battery \
tmux-plugins/tmux-cpu \
tmux-plugins/tmux-prefix-highlight \
'
#tmux-sensible - A set of tmux options that should be acceptable to everyone.Inspired by vim sensible
#tmux-resurrect - Persists tmux environment across system restarts.
#tmux-yank - Tmux plugin for copying to system clipboard
#tmux-pain-control - Tmux plugin for controlling panes. Adds standard pane navigation bindings.
#tmux-copycat - This plugin enables: regex searches, search result highlighting, predefined searches
#tmux-open - Plugin for opening highlighted selection directly from Tmux copy mode (with o and ctrl+o)
#tmux-continuum - Continuous saving of tmux environment. Automatic restore when tmux is started. Automatic tmux start when computer is turned on.
#tmux-battery - Plug and play batter percentage and icon indicator
#tmux-cpu - Plug and play cpu percentage and icon indicator for Tmux
#tmux-prefix-highlight - Plugin that highlights when you press tmux prefix key
# Other examples:
# set -g @plugin 'github_username/plugin_name'
# set -g @plugin '[email protected]/user/plugin'
# set -g @plugin '[email protected]/user/plugin'
#tmux navigator remaps ctrl+l which clears the screen in tmux nicely, so remap it to PREFIX+ctrl+t
# see https://github.com/christoomey/vim-tmux-navigator
bind C-t send-keys 'C-l'
#vim-tmux-navigator remaps (previously used the plugin for remaps, but fzf needed accomodating)
is_vim="ps -o state= -o comm= -t '#{pane_tty}' \
| grep -iqE '^[^TXZ ]+ +(\\S+\\/)?g?(view|n?vim?x?)(diff)?$'"
is_fzf="ps -o state= -o comm= -t '#{pane_tty}' \
| grep -iqE '^[^TXZ ]+ +(\\S+\\/)?fzf$'"
bind -n C-h run "($is_vim && tmux send-keys C-h) || \
tmux select-pane -L"
bind -n C-j run "($is_vim && tmux send-keys C-j) || \
($is_fzf && tmux send-keys C-j) || \
tmux select-pane -D"
bind -n C-k run "($is_vim && tmux send-keys C-k) || \
($is_fzf && tmux send-keys C-k) || \
tmux select-pane -U"
bind -n C-l run "($is_vim && tmux send-keys C-l) || \
tmux select-pane -R"
#explaining the single quoted backslashes: https://github.com/tmux/tmux/issues/1827
bind-key -n 'C-\' if-shell "$is_vim" "send-keys C-\\" "select-pane -l"
bind-key -T copy-mode-vi C-h select-pane -L
bind-key -T copy-mode-vi C-j select-pane -D
bind-key -T copy-mode-vi C-k select-pane -U
bind-key -T copy-mode-vi C-l select-pane -R
bind-key -T copy-mode-vi 'C-\' select-pane -l
#tmux-continuum settings - see https://github.com/tmux-plugins/tmux-continuum/blob/master/docs/automatic_start.m://github.com/tmux-plugins/tmux-continuum/blob/master/docs/automatic_start.md
set -g @continuum-boot-options 'iterm'
set -g @continuum-boot 'on'
set -g @continuum-restore 'on'
set -g @continuum-save-interval 15
# problem is this affects the NON-maglev status line (i can see it when i haven't got maglev enabled)
set -g status-right 'Continuum status: #{continuum_status}'
# tmux-yank setings
# https://github.com/tmux-plugins/tmux-yank#controlling-yank-behavior - stops a yank taking you out of copy mode and back to the bottom of the terminal. to go back to the old behaviour just hit reuturn after the yank
# found via https://github.com/tmux/tmux/issues/402
# update on that for tmux 3.0, from the tmux changelog from 2.9 to 3.0:
# > * Add -no-clear variants of copy-selection and copy-pipe which do not clear the selection after copying. Make copy-pipe clear the selection by default to be consistent with copy-selection.
# hence for >3.0 compatibility, to not clear the selection on mouse selection (just like keyboard selection). I changed 'copy-pipe' below to 'copy-pipe-no-clear'
set -g @yank_action 'copy-pipe-no-clear' # or 'copy-pipe-and-cancel' for the default
# tmux-ressurect options
# firstly, I use MacVim (for YouCompleteMe support). Yes I symlink it to vim in applications, but not according to tmux-ressurect
# (see its 'last' file in /usr/local/Cellar/macvim/8.0-133/MacVim.app/Contents/bin/../MacOS/Vim resurrect/last)
# its not on the default list of apps to be restored, only macvim is
# see here: https://github.com/tmux-plugins/tmux-resurrect/issues/75
# Note the tilde before the MacVim.app. That means that any process that matches that string will be restored.
# I just copied the whole line below from the issue ticket there, not sure why git log in particular, doesn't hurt...
set -g @resurrect-processes 'vim mvim nvim lvim "git log" "~MacVim.app"'
# for vim
set -g @resurrect-strategy-vim 'session'
# for neovim
set -g @resurrect-strategy-nvim 'session'
set -g @resurrect-capture-pane-contents 'on' #however it says tmux-sensible should already do this
set -g @resurrect-save-shell-history 'off' #this used to be on, but wouldn't have worked for zsh, then zsh feature was added, but side effects were severe - see https://github.com/tmux-plugins/tmux-resurrect/issues/278
# First-run only: to initialise the TMUX plugin manager, we'll need the TMUX plugin manager, and if we didn't have the tmux plugin manager, we will need the plugins installing (saving us from having to manually [prefix] + I )
# see https://github.com/tmux-plugins/tpm/issues/6, also for future docker requirements
# 2 minor issues: 1) we install all plugins in silence THEN tell you what happened, and we'll run the tpm initialisation twice (i think its confusing if you incorporate the standard init in this first-time only flow). Neither seems to make much difference...
run 'if ! [[ -f ~/.tmux/plugins/tpm/tpm ]]; then echo "downloaded the tmux plugin manager [enter to continue]" && git clone https://github.com/tmux-plugins/tpm ~/.tmux/plugins/tpm && ~/.tmux/plugins/tpm/tpm && ~/.tmux/plugins/tpm/scripts/install_plugins.sh ; fi'
# Initialize TMUX plugin manager (keep this line at the very bottom of tmux.conf)
run '~/.tmux/plugins/tpm/tpm'