Ivan Tomica

My Tmux configuration

I’ve spent some time tweaking and playing around with my .tmux.conf. If you’re interested in how I did it or search for some inspiration you can find my configuration at the bottom of this post. I’ll briefly explain and showcase some of the options throughout the article.

To reload config without closing and re-opening Tmux again I’ve mapped Prefix + r as key combination to source ~/.tmux.conf:

# Reload config
bind r source-file ~/.tmux.conf

Green bar at the bottom was too ugly for me so I’ve customized it a bit. On the left hand side short hostname is displayed while on the right hand side there’s simple clock. Here’s how it looks:

Mouse should not interfere with tmux in any way so I’ve also disabled it, following code is needed to determine which tmux version is in use and to set appropriate option as option names differ between versions:

if-shell "[[ `tmux -V | cut -d' ' -f2` -lt 2.1 ]]" "setw -g mode-mouse off"
if-shell "[[ `tmux -V | cut -d' ' -f2` -ge 2.1 ]]" "setw -g mouse off"

I like to be notified about changes within the pane, but hate when text pops up and poops my status bar, so to enable monitor but disable message, use:

setw -g monitor-activity on
set -g visual-activity off

If you use same session on multiple computers and resize terminal window regularly you know how stupid it is when size of the window becomes smaller and smaller and doesn’t resize after you detach from session on that small terminal window. Anyhow, here’s a way to fix that:

setw -g automatic-rename on
setw -g aggressive-resize on

Here’s my whole .tmux.conf file, it is pretty well documented and straight forward simple as most of the tmux options are self-explanatory, so, enjoy:

# Reload config
bind r source-file ~/.tmux.conf

# Rename terminals
set -g set-titles on
set -g set-titles-string '#H'

set -g default-terminal "screen-256color"

# Address vim mode switching delay
set -s escape-time 0

# Status bar customization
set -g status-bg black
set -g status-fg white
set -g status-left '#[bg=black,fg=blue,bold][#[fg=white]#h#[fg=blue,bold]] '
set -g status-left-length 30
set -g status-right '#[fg=blue,bold][#[fg=white]%Y-%m-%d %H:%M#[fg=blue]]'
set -g status-right-length 30
set -g status-justify left

# Window bar customization
setw -g window-status-current-format '#[fg=black]#[bg=white]#I#F#W#[default]'
setw -g window-status-activity-bg white
setw -g window-status-activity-fg red
setw -g window-status-separator " | "

# Disable mouse
if-shell "[[ `tmux -V | cut -d' ' -f2` -lt 2.1 ]]" "setw -g mode-mouse off"
if-shell "[[ `tmux -V | cut -d' ' -f2` -ge 2.1 ]]" "setw -g mouse off"

setw -g automatic-rename on
setw -g aggressive-resize on

# Enable activity but disable pane message
setw -g monitor-activity on
set -g visual-activity off

# Start pane numbering from 1
set -g base-index 1
setw -g pane-base-index 1

# Set 0 to go to 10 (re-numbering)
bind 0 select-window -t :10

# Automatically renumber windows
set -g renumber-windows on

# Increase scrollback history
set -g history-limit 10000

# Remap pane navigation to Vi mode
unbind-key j
unbind-key k
unbind-key h
unbind-key l

bind-key j select-pane -D
bind-key k select-pane -U
bind-key h select-pane -L
bind-key l select-pane -R

# Pane resizing
bind -r M-h resize-pane -L 5
bind -r M-j resize-pane -D 5
bind -r M-k resize-pane -U 5
bind -r M-l resize-pane -R 5

# Move windows with Prefix + < and >
bind -r < swap-window -t -1
bind -r > swap-window -t +1

If you have any unknowns about some option in config file, look up in manpage ;-) Or you can ask in the comment section.

Tagged in:, ,
Sysadmin on the everlasting journey of learning. Always in search for an opportunity to prove myself and to learn something new. My addiction is learning and my main goal is to excel in every aspect of Linux/Unix system administration.


Leave a Reply

Your email address will not be published. Required fields are marked *