[Ubuntu] My .tmux.conf

7 minute read

My .tmux.conf

run-shell 'tmux setenv -g TMUX_VERSION $(tmux -V | \
                                    sed -En "s/^tmux ([0-9]+(.[0-9]+)?).*/\1/p")'

set -g default-terminal "screen-256color"
set-option -g default-shell /usr/bin/zsh

# ***WARNING!*** tmux will exit immediately if this plugin is not installed!!!
# http://superuser.com/questions/397076/tmux-exits-with-exited-on-mac-os-x
# set-option -g default-command "reattach-to-user-namespace -l $SHELL"

if-shell -b '[ "$(echo "$TMUX_VERSION < 2.2" | bc)" = 1 ]' \
          "set -g utf8 on; set -g status-utf8 on; set -g mouse-utf8 on"
#setw -gq utf8 on
#set -g status-utf8 on

# change default prefix (C-b) to (C-a)
unbind C-a
set -g prefix C-a
bind C-a send-prefix

set-option -g repeat-time 10000

# allow xterm keys
set-window-option -g xterm-keys on

# start numbering from 1 instead of 0
set -g base-index 1

# bind C-a C-a to last active window
bind-key C-a last-window

# get rid of delay reading command characters while tmux waits for escape sequence
set -s escape-time 1

# reload ~/.tmux.conf using prefix r
bind r source-file ~/.tmux.conf \; display "tmux reloaded"

# change split prefixes (horizontal: C-space /) (vertical: C-space -)
bind / split-window -h
bind - split-window -v

# make current window the 1st window
bind T swap-window -t -1
bind t swap-window -t +1

# set scrollback history to 10K lines
set -g history-limit 1000000

# mouse support
if-shell "tmux -V |awk ' {split($2, ver, \".\"); if (ver[1] < 2) exit 1 ; else if (ver[1] == 2 && ver[2] < 1) exit 1 }' " 'source ~/.tmux/gt_2.0.conf' 'source ~/.tmux/lt_2.1.conf'

# vi
# ==
setw -g mode-keys vi
set -g status-keys vi

# setup 'v' to begin selection as in vim
# <= 2.4
if-shell -b '[ "$(echo "$TMUX_VERSION < 2.4" | bc)" = 1 ]' " \
        bind-key -t vi-edit Up history-up; \
        bind-key -t vi-edit Down history-down; \
        unbind-key -t vi-copy Space; bind-key -t vi-copy v begin-selection; \
        unbind-key -t vi-copy Enter; bind-key -t vi-copy y copy-pipe 'reattach-to-user-namespace pbcopy'; \
        unbind-key -t vi-copy C-v  ; bind-key -t vi-copy C-v rectangle-toggle; \
        unbind-key -t vi-copy [    ; bind-key -t vi-copy [ begin-selection; \
        unbind-key -t vi-copy ]    ; bind-key -t vi-copy ] copy-selection"

# < 2.9
if-shell -b '[ "$(echo "$TMUX_VERSION < 2.9" | bc)" = 1 ]' " \
        bind-key -T edit-mode-vi Up history-up; \
        bind-key -T edit-mode-vi Down history-down; \
        unbind-key -T copy-mode-vi Space ; bind-key -T copy-mode-vi v send-keys -X begin-selection; \
        unbind-key -T copy-mode-vi Enter ; bind-key -T copy-mode-vi y send-keys -X copy-pipe-and-cancel 'reattach-to-user-namespace pbcopy'; \
        unbind-key -T copy-mode-vi C-v   ; bind-key -T copy-mode-vi C-v send-keys -X rectangle-toggle; \
        unbind-key -T copy-mode-vi [     ; bind-key -T copy-mode-vi [ send-keys -X begin-selection; \
        unbind-key -T copy-mode-vi ]     ; bind-key -T copy-mode-vi ] send-keys -X copy-selection"

# map vi movement keys as pane movement keys
bind h select-pane -L
bind j select-pane -D
bind k select-pane -U
bind l select-pane -R

# use vi left and right to cycle thru panes
bind -r C-h select-window -t :-
bind -r C-l select-window -t :+

# resize panes using vi keys
bind -r H resize-pane -L 5
bind -r J resize-pane -D 5
bind -r K resize-pane -U 5
bind -r L resize-pane -R 5

# window status
# =============
set-option -g automatic-rename off
set-option -g allow-rename off
setw -g window-status-format " #F#I:#W#F "
setw -g window-status-current-format " #F#I:#W#F "
setw -g window-status-format "#[fg=magenta]#[bg=black] #I #[bg=cyan]#[fg=colour8] #W "
setw -g window-status-current-format "#[bg=brightmagenta]#[fg=colour8] #I #[fg=colour8]#[bg=colour14] #W "
setw -g window-status-current-bg colour0
setw -g window-status-current-fg colour11
setw -g window-status-current-attr dim
setw -g window-status-bg green
setw -g window-status-fg black
setw -g window-status-attr reverse

# panes
# =====
set -g pane-border-fg colour255
set -g pane-active-border-fg colour214

# status bar
# ==========
set -g status-justify left
set -g status-position bottom
set -g status-bg colour234
set -g status-fg colour137
set -g status-attr dim
set -g status-left '#[fg=colour233,bg=colour245,bold] [#S] '
set -g status-right '#[fg=colour233,bg=colour241,bold] %d/%m #[fg=colour233,bg=colour245,bold] %H:%M:%S '
set -g status-right-length 50
set -g status-left-length 20

setw -g window-status-current-fg colour81
setw -g window-status-current-bg colour238
setw -g window-status-current-attr bold
setw -g window-status-current-format ' #I#[fg=colour250]:#[fg=colour255]#W#[fg=colour50]#F '

setw -g window-status-fg colour138
setw -g window-status-bg colour235
setw -g window-status-attr none
setw -g window-status-format ' #I#[fg=colour237]:#[fg=colour250]#W#[fg=colour244]#F '

setw -g window-status-bell-attr bold
setw -g window-status-bell-fg colour255
setw -g window-status-bell-bg colour1

set-option -g set-titles on

# quiet!
setw -g monitor-activity off
set -g monitor-silence 0
set -g bell-action none

set -g visual-activity off
set -g visual-bell off
set -g visual-silence off