# Use Ctrl-A instead of Ctrl-B.
set -g prefix C-a
unbind C-b
bind C-a send-prefix
# Disable the status bar. The window title is sufficient.
set -g status off
# Automatically renumber windows when one is killed.
set -g renumber-windows on
# This is apparently necessary for a terminal's "focus" events to get passed
# through. This is required, for example, for neovim's `FocusGained` event to
# fire. And that is in turn necessary for my file auto-reloading hack to work
# like you'd expect.
#
# See: https://github.com/alacritty/alacritty/issues/572
set -g focus-events on
# Use 256 colors.
# set -g default-terminal "xterm-256color"
set -g default-terminal "tmux-256color"
# This is to make tmux support truecolor. neovim suggested it via checkhealth.
set-option -sa terminal-overrides ',*-256color:RGB'
# This is set to make tmux support hyperlinks. But this requires at least tmux
# 3.4, which currently needs to be built from source. (tmux-git package on
# Archlinux.)
set-option -sa terminal-features ",*:hyperlinks"
# Let OSC 52 escape sequences work for copy/paste.
set -g set-clipboard on
set -g allow-passthrough on
# Set history limit ridiculously high.
set -g history-limit 1073741824
# Don't add any delay for pressing the escape key.
# Without this, vim becomes *really* annoying to use.
# The default is 500ms. Reduce it substantially.
set -g escape-time 20
# Set the appropriate title.
set -g set-titles on
# set -g set-titles-string "#(pwd)"
# Always use vim keybindings.
set -g mode-keys vi
# Start window numbering at 1.
set -g base-index 1
# Convenient config reloading.
bind r source-file "$HOME/.tmux.conf"
# Switch back and forth between windows, screen-style.
bind a last-window
bind C-a last-window
# Swap the current window with the "left" and "right" windows.
bind-key Left swap-window -t -1\; select-window -t -1
bind-key Right swap-window -t +1\; select-window -t +1
# When opening a new window, use the CWD.
unbind c
bind c new-window -c "#{pane_current_path}"
# Use saner splitting commands.
unbind %
unbind '"'
bind h split-window -h -c "#{pane_current_path}"
bind v split-window -v -c "#{pane_current_path}"
# Use '"' to list windows, like in Screen.
# Leave tmux's 'w' binding though.
# Also, support tmux 2.5, which has different `choose-tree` defaults.
if-shell 'tmux -V | grep "tmux 2.5"' 'bind "\"" choose-tree -u' 'bind "\"" choose-tree -s'
if-shell 'tmux -V | grep "tmux 2.5"' 'bind w choose-tree -u' 'bind w choose-tree -w'
# Nicer shortcuts for toggling between layouts.
unbind z
unbind Z
bind z select-layout even-vertical
bind Z select-layout even-horizontal
# Vim copying.
unbind -T copy-mode-vi v
unbind -T copy-mode-vi y
bind -T copy-mode-vi v send -X begin-selection
bind -T copy-mode-vi C-v send -X rectangle-toggle
bind -T copy-mode-vi y send -X copy-selection
# Make it easier to enter copy-mode.
bind -T root S-Up copy-mode \; send -X scroll-up
bind -T root S-Down copy-mode \; send -X scroll-down
bind -T root S-PageUp copy-mode \; send -X halfpage-up
bind -T root S-PageDown copy-mode \; send -X halfpage-down
# Don't be so overeager with paging.
bind -T copy-mode-vi S-PageUp send -X halfpage-up
bind -T copy-mode-vi S-PageDown send -X halfpage-down
bind -T copy-mode-vi PageUp send -X halfpage-up
bind -T copy-mode-vi PageDown send -X halfpage-down
# Renumber session automatically.
set-hook -g session-created "run-shell $HOME/bin/tmux-cleanup \; run-shell $HOME/bin/tmux-renumber-sessions"
set-hook -g session-closed "run-shell $HOME/bin/tmux-cleanup \; run-shell $HOME/bin/tmux-renumber-sessions"
# Open a new terminal in the CWD.
bind C-n run-shell -b "$HOME/bin/terminal -d #{pane_current_path} -- tmux -u new -c #{pane_current_path} zsh"
# Track fresh values for new windows.
set -g update-environment "DISPLAY SSH_AUTH_SOCK SSH_AGENT_PID SSH_CONNECTION"