tmux conf
13 Sep 2021
Everybody's gotta have a tmux conf. This one has been working for me.
# Make ctrl-k the prefix
set -g prefix C-k
# Make ctrl-b no longer a prefix
unbind C-b
# vim mode
setw -g mode-keys vi
# copy paste
unbind-key -T prefix Escape
bind-key   -T prefix Escape 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
bind-key   -T copy-mode-vi Escape send-keys -X cancel
# use 'p' to paste buffer
unbind-key -T prefix p
bind-key   -T prefix p paste-buffer
# First have to yank with y but then Leader, Ctrl-c will copy to system clibpoard.
# Though there seems to be a system freeze after doing so.
# $ sudo apt install xclip
# bind C-c run "tmux save-buffer - | xclip -i -sel clipboard"
# lots and lots of history
set -g history-limit 100000
# 256 colors of course
set -g default-terminal "screen-256-color"
# Turn off mouse support
set -g mouse off
# Style things better
set -g status-style fg=white,bold,bg=black
set -g window-status-style fg=white,bg=black
#set -g window-status-current-style fg=black,bold,bg=yellow
set -g window-status-current-style fg=black,bold,bg=colour11
set -g message-style fg=white,bold,bg=black
# Don't particularly care about showing the session name
set -g status-left "[#S] "
# This was a neat way to show the current dir, but current
# dir is already in my bash prompt.
# set -g status-right "[#{=-38:pane_title}]"
set -g status-right ""
# Set delay between prefix and command
# to ideally not miss with vim
set -s escape-time 1
# Set base index for windows to 1 instead of 0
set -g base-index 1
# Set the base index for panes to 1 instead of 0
set -g pane-base-index 1
# ------------ keys -------------------
# Remember current bindings:
# prefix w --> brings up a navigable list of windows.
# prefix Esc --> go to scroll/copy mode.
# prefix p --> paste from selection.
# prefix d --> detach from session.
# Use 'n' to mean "new window"
unbind-key -T prefix n
bind-key   -T prefix n command-prompt -p "window name:" "new-window; rename-window '%%'"
# Use 'r' to mean "rename window"
unbind-key -T prefix r
bind-key   -T prefix r command-prompt -p "rename #W to:" "rename-window -- '%%'"
# split panes
unbind-key -T prefix \\
bind-key   -T prefix \\ split-window -h
unbind-key -T prefix -
bind-key   -T prefix - split-window -v
# "Evict" a pane into its own window
unbind-key -T prefix e
bind-key   -T prefix e command-prompt -p "evict to window:" "break-pane -d -n '%%'"
# "Grab" a window by making it a pane in the current window
unbind-key -T prefix g
bind-key   -T prefix g command-prompt -p "grab window:" "join-pane -h -s '%%'"
# navigate panes
unbind-key -T prefix h
bind-key   -T prefix h select-pane -L
unbind-key -T prefix j
bind-key   -T prefix j select-pane -D
unbind-key -T prefix k
bind-key   -T prefix k select-pane -U
unbind-key -T prefix l
bind-key   -T prefix l select-pane -R
# Layout panes like books (vertically beside each other on a shelf)
unbind-key -T prefix |
bind-key   -T prefix | select-layout even-horizontal
# Layout panes like cake (horizontally stacked layers of a layer cake)
unbind-key -T prefix _
bind-key   -T prefix _ select-layout even-vertical
# Clear terminal and clear tmux history for window
unbind-key -T prefix c
bind-key   -T prefix c send-keys clear Enter \; clear-history