# Reload Tmux configuration bind-key r source-file ~/.tmux.conf \; display-message "~/.tmux.conf reloaded" # Enable Tmux's mouse mode. # # In iTerm, this mostly does what I want, in that it allows me to click on # things to bring them into focus (windows, panes). It also handles scrolling # more elegantly. set-option -g mouse on # Mouse mode isn't perfect. By default, ending a drag cancels the selection, # which is a jarring on non-default behaviour. This makes sure this doesn't # happen anymore. unbind-key -T copy-mode MouseDragEnd1Pane # Because we cancelled the mouse drag ending a selection, we don't have an # easy and convenient way to make get back to normal. When using a GUI, a # single click usually does the trick. This command restores that behaviour. bind-key -T copy-mode MouseUp1Pane send-keys -X cancel # Use the Vim yank mnemonic to commit a copy when in copy mode. # I don't actually hit "y" to copy, though. In iTerm, I have Cmd+C set up # to send the hexcode for y to the terminal, which means the normal macOS # copy shortcut does the right thing, so long as I'm in Tmux. bind-key -T copy-mode y send-keys -X copy-pipe "pbcopy" # When I delete a window, relabel them automatically. set-option -g renumber-windows on # Pane switching. These interface with Vim to ensure that pane switching is # both consistent and sensible. # # Borrowed from Chris Toomey: https://github.com/christoomey/vim-tmux-navigator is_vim="ps -o state= -o comm= -t '#{pane_tty}' \ | grep -iqE '^[^TXZ ]+ +(\\S+\\/)?g?(view|n?vim?x?)(diff)?$'" bind-key -n C-h if-shell "$is_vim" "send-keys C-h" "select-pane -L" bind-key -n C-j if-shell "$is_vim" "send-keys C-j" "select-pane -D" bind-key -n C-k if-shell "$is_vim" "send-keys C-k" "select-pane -U" bind-key -n C-l if-shell "$is_vim" "send-keys C-l" "select-pane -R" bind-key -n C-\ if-shell "$is_vim" "send-keys C-\\" "select-pane -l" # When zooming a pane in a window, also zoom the vim split bind-key z if-shell "$is_vim" "resize-pane -Z \; send-keys C-z" "resize-pane -Z" # All pane and window creations use the same path as the current process, # which I have found to be a good default. # # I don't typically hit c to open a new window, I have that bound # to Cmd+T in iTerm the same way I manage the clipboard. I also add the # tab traversal shortcuts to move between Tmux windows. bind-key c new-window -c "#{pane_current_path}" # Backslash is the unshifted version of | bind-key \ split-window -h -c '#{pane_current_path}' # Ditto, hyphen is the unshifted version of _ bind-key - split-window -v -c '#{pane_current_path}'