tmux.conf 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. #-----------------------------
  2. # ~ tmux.conf ~ for Chris Jones
  3. # github > @ipatch
  4. # twitter > @truckmonth
  5. ##
  6. #-----------------------------
  7. # NOTE: `display` is short for `display-message`
  8. # NOTE: `bind` is short for `bind-key`
  9. # NOTE: `-n` option when creating a key-binding does not require the prefix
  10. # NOTE: `set-option` controls the look / feel of tmux.
  11. # NOTE: official tmux documentation,
  12. # ... https://github.com/tmux/tmux/wiki/FAQ
  13. # ....uses double quotes and not single.
  14. ##
  15. # remove all previous bindings, useful when exp with new bindings,
  16. # and old ones aren't removed, see: https://unix.stackexchange.com/a/57648/33002
  17. # unbind-key -a
  18. # NOTE: the default "prefix" key in tmux is `C-b` ie. <Control>+b
  19. unbind C-b # ubind `C-b` 🤸
  20. # NOTE: `-g` flag makes the `prefix` global to ALL tmux sessions.
  21. set -g prefix C-s # reassign the `prefix` key.
  22. bind r source-file ~/.tmux.conf \; display "~/.tmux.conf reloaded"
  23. # Neovim recommends the below `escape` time setting
  24. set -sg escape-time 10
  25. set -g default-terminal "tmux-256color" # use custom compiled terminfo file
  26. set-option -sa terminal-overrides ',xterm*:Tc' # enable 24 bit color
  27. #
  28. # NOTE: setting this to `fish` solves my issues related to out of order $PATH entries
  29. # REF: https://unix.stackexchange.com/a/548516/33002
  30. # NOTE: TODO: below setting may be problematic if the fish shell is not installed on box
  31. set-option -g default-command fish
  32. ## nova's
  33. # set -ga terminal-overrides ",screen-256color:Tc"
  34. # set -as terminal-overrides ',xterm*:Tc:sitm=\E[3m'
  35. # Experimental
  36. set-window-option -g xterm-keys on
  37. #-----------------------------
  38. # STYLES / STYLING / status line / bar
  39. # NOTE: to print options that can be styled `tmux show -g`
  40. ##
  41. # NOTE: `set` is short for `set-option`, it is an internal alias within tmux.
  42. # set -g utf8 on #INVALID, nova
  43. set -g status-bg "#3e93b2"
  44. set -g status-fg "#01070a"
  45. set -g status-justify centre # center the window list in status line
  46. # NOTE: the below option sets / displays the tmux session name up to 50 characters long. It can be seen in the lower left of the tmux status bar.
  47. set -g status-left-length 50
  48. set -g status-left "#S #{?client_prefix,#[fg=colour208]^S,}" # modify the default left status bar, rm `[]`
  49. set -g status-right "#(~/.local/bin/battery) #[fg=purple]%d %b %R"
  50. # styles for windows
  51. ## styles for current active window
  52. ### TODO: see repo README, for style window titles to fit zoom icon into empty space
  53. ### ...presently zoom icon appends to window name, thus moving layout of all text in status bar ...BOO!
  54. setw -g window-status-current-format "#[fg=#000000]#[bg=colour208]#I:#W#{?window_zoomed_flag,🔍,}#{?pane_synchronized,🏊🏊,}"
  55. ## styles for inactive windows, ie. background windows
  56. setw -g window-status-format "#I:#W#{?window_zoomed_flag,🔍,}#{?pane_synchronized,🏊🏊,}"
  57. #----------------------------
  58. # STYLES / STYLING / panes
  59. ## NOTE: may be deprecated in tmux ≥ 2.9
  60. #--------------
  61. # borders
  62. # set-option -g pane-active-border-bg default
  63. # set-option -g pane-active-border-fg colour208 # an orangish unbuntu color
  64. #-----------------------------
  65. # History
  66. # NOTE: to remove scroll back history within a tmux pane `prefix + ctrl+k`
  67. ##
  68. bind C-l send-keys "C-l" # `prefix + C-l` to clear the screen
  69. bind C-k send-keys -R \; send-keys "C-l" \; clear-history
  70. set -g history-limit 200000 # Scrollback for weeks (default is 2000)
  71. # toggle pane syncronization
  72. bind e setw synchronize-panes
  73. #-----------------------------
  74. # Winow / pane splitting
  75. ##
  76. # TODO: tmux requires adding single quotes around `-` and `\` whereas prior versions did not
  77. # ...time permitting conditionally change settings based tmux version if not backward compatible
  78. # split pane and preserve path
  79. bind '-' split-window -v -c "#{pane_current_path}"
  80. bind '\' split-window -h -c "#{pane_current_path}"
  81. # exp, get pane from different window and put within the current window
  82. # TODO: provide example of how cmd works
  83. bind-key @ command-prompt -p "create pane from:" "join-pane -s ':%%'"
  84. #-----------------------------
  85. # NOTE: `setw` is short for `set-window-option`
  86. ##
  87. setw -g base-index 1 # begin window numbering at 1 instead of 0
  88. setw -g renumber-windows on
  89. setw -g mode-keys vi # Vim style navigation in copy mode
  90. set -g default-shell $SHELL
  91. set -g mouse on
  92. #-----------------------------
  93. # Set keys for easier window management
  94. ##
  95. # NOTE: going to use below binding to create a new nested tmux session
  96. # bind -n C-n new-window -c "#{pane_current_path}" # new window preserve path
  97. #
  98. # Create a new nested tmux (prefix + ctrl + n)
  99. bind C-n new-window ~/.tmux.conf.d/nested-tmux/new-tmux \; \
  100. rename-window '' \; \
  101. command-prompt -I "#W" "rename-window -- '%%'"
  102. bind -n S-down new-window -c "#{pane_current_path}" # new window preserve path
  103. # bind -n C-down new-window -c "#{pane_current_path}" # new window preserve path
  104. # bind-key -n space next-window # goto the next window
  105. # bind-key -n bspace previous-window # goto the previous window
  106. bind -n S-right next-window
  107. bind -n S-left previous-window
  108. bind-key h swap-window -t :- # move window to the left
  109. # NOTE: TODO: tmp disable binding, to exp with switching between present and last window
  110. # bind-key l swap-window -t :+ # move window to the right
  111. bind-key l last-window # switch to previous window
  112. #-----------------------------
  113. # seemless integration between vim & tmux keybindings
  114. #-
  115. # Smart pane switching with awareness of Vim splits.
  116. # See: https://github.com/christoomey/vim-tmux-navigator
  117. # See: https://github.com/christoomey/vim-tmux-navigator/issues/218#issuecomment-495002332
  118. is_vim="ps -o state= -o comm= -t '#{pane_tty}' \
  119. | grep -iqE '^[^TXZ ]+ +(\\S+\\/)?g?(view|vim|nvim|ssh|mosh|tmux?)(diff)?$'"
  120. # is_vim="ps -o state= -o comm= -t '#{pane_tty}' \
  121. | grep -iqE '^[^TXZ ]+ +(\\S+\\/)?g?(view|n?vim?x?)(diff)?$'"
  122. bind-key -n 'C-h' if-shell "$is_vim" 'send-keys C-h' 'select-pane -L'
  123. bind-key -n 'C-j' if-shell "$is_vim" 'send-keys C-j' 'select-pane -D'
  124. bind-key -n 'C-k' if-shell "$is_vim" 'send-keys C-k' 'select-pane -U'
  125. bind-key -n 'C-l' if-shell "$is_vim" 'send-keys C-l' 'select-pane -R'
  126. tmux_version='$(tmux -V | sed -En "s/^tmux ([0-9]+(.[0-9]+)?).*/\1/p")'
  127. if-shell -b '[ "$(echo "$tmux_version < 3.0" | bc)" = 1 ]' \
  128. "bind-key -n 'C-\\' if-shell \"$is_vim\" 'send-keys C-\\' 'select-pane -l'"
  129. if-shell -b '[ "$(echo "$tmux_version >= 3.0" | bc)" = 1 ]' \
  130. "bind-key -n 'C-\\' if-shell \"$is_vim\" 'send-keys C-\\\\' 'select-pane -l'"
  131. bind-key -T copy-mode-vi 'C-h' select-pane -L
  132. bind-key -T copy-mode-vi 'C-j' select-pane -D
  133. bind-key -T copy-mode-vi 'C-k' select-pane -U
  134. bind-key -T copy-mode-vi 'C-l' select-pane -R
  135. # bind-key -T copy-mode-vi 'C-\' select-pane -l
  136. #------------------------------
  137. #- smart pane switching
  138. #- NOTE: 🔥 below key mappings are req'd for switching between panes when using ssh
  139. #--
  140. bind-key -n C-h run "(tmux display-message -p '#{pane_current_command}' | grep -iqE '(vim|emacs)' && tmux send-keys C-h) || tmux select-pane -L"
  141. bind-key -n C-j run "(tmux display-message -p '#{pane_current_command}' | grep -iqE '(vim|emacs)' && tmux send-keys C-j) || tmux select-pane -D"
  142. bind-key -n C-k run "(tmux display-message -p '#{pane_current_command}' | grep -iqE '(vim|emacs)' && tmux send-keys C-k) || tmux select-pane -U"
  143. bind-key -n C-l run "(tmux display-message -p '#{pane_current_command}' | grep -iqE '(vim|emacs)' && tmux send-keys C-l) || tmux select-pane -R"
  144. ##############################
  145. # TERM adapting tmux to work with term title bars
  146. ##
  147. set -g set-titles on # set-titles-string
  148. set -g set-titles-string "#{session_name} - #T"
  149. # rename window or pane to current job or process.
  150. # NOTE: doesn't play nice with `Terminal.app`
  151. set -g automatic-rename on
  152. ##############################
  153. ##
  154. set -g monitor-activity on # highlight windows that have unseen activity
  155. set -g visual-activity off # don't show a notification when there is activity in a window
  156. ##############################
  157. # Logging
  158. ##
  159. bind P pipe-pane -o "cat >>~/logs/#W.tmux.log" \; display "Toggled logging to ~/logs/#W.tmux.log"
  160. ##############################
  161. # `reattach-to-user-namespace` macos specific
  162. # NOTE: reattach-to-user-namespace is not required for tmux ≥ 2.6
  163. # TODO: is possible to check if tmux ≥ 2.6 and conditionally not load config
  164. ##
  165. if-shell "uname | grep -q Darwin" "source-file ~/.tmux/tmux.macos.conf"
  166. ##############################
  167. # double tap, doubletap left shift
  168. ##
  169. # NOTE: below option requires `-g` flag
  170. # NOTE: this broke when tmux was upgraded to 3.2a i believe
  171. # TODO: fix broken double tap
  172. set-option -g prefix2 "C-S-M-f1" # WORK!!!
  173. bind-key C-S-M-f1 resize-pane -Z # toggle min/max pane in window, prefix not required
  174. # double tap left shift relies on ke for macos
  175. ##############################
  176. # tmux 1.9+ SEE: `man tmux` for more info
  177. ##
  178. set-option -g focus-events on
  179. ##############################
  180. # tmux / DANGER ZONE!!!! / place to break current tmux config, and store experimental features
  181. ##
  182. # NOTE: list available tmux commands
  183. # tmux: list-commands
  184. # :list-commands
  185. # move-pane
  186. # resize-pane
  187. # bind-key -n F11 display "F11 pressed"
  188. # unbind-key -n F11 # NOTE: the `-n` flag is required
  189. # TODO: eventually want `F12` to toggle between local and remote / nested tmux session
  190. # bind-key -n F12 display "F12 pressed"
  191. #SEE: https://gist.github.com/ipatch/514e60d8eae01d7e461e68305d96316d for why `bind-key` is required
  192. unbind-key -n F12 # NOTE: the `-n` flag is required
  193. # TODO: tmux add aditional key binding
  194. # TODO: tmux add keypress then keypress binding
  195. # bind -n shift shift resize-pane
  196. # NOTE: `bind -T root` == `bind -n`
  197. # bind -T root F12 \
  198. # bind -T root '"\e[24~"' \
  199. # bind -n F12
  200. # set prefix None \;\
  201. # set key-table off \;\
  202. # adjust color of status bar
  203. # set -g status-bg "#3e93b2" # default `blue background color"
  204. # set -g status-bg "#9b9b9b" # light grey # LINK: https://www.color-hex.com/color-wheel/
  205. # if-shell -F '#{pane_in_mode}' 'send-keys -X cancel' \;\
  206. refresh-client -S \;\
  207. # bind-key -n off F12 \
  208. set -u prefix \;\
  209. set -u key-table \;\
  210. # set -u status-style \;\
  211. # set -g status-bg "#3e93b2" # default `blue background color"
  212. # refresh-client -S
  213. ##############################
  214. # tmux - plugins
  215. ##
  216. set -g @plugin "tmux-plugins/tpm"
  217. set -g @plugin "tmux-plugins/tmux-resurrect"
  218. ##############################
  219. # tmux > plugin > tmux-resurrect
  220. ##
  221. set -g @resurrect-strategy-nvim 'session'
  222. # Initialize TMUX plugin manager
  223. # 🚨 ALERT: 👇 must be last line in `tmux.conf`
  224. run "~/.tmux/plugins/tpm/tpm"