My tmux setup

Are you using tmux? If not, why not? Let me debunk some myths and misconceptions in this post and share my tmux setup with you in the hope to convince you to start using it as well.

I don’t know about you, but I do spend a fair amount of my day in the terminal. Usually, I’ve got a number of projects open I’m working on, each with its setup such as current directory, environment variables, and so forth:

tmux overview

I first came across screen and wasn’t sold. Then, I saw tmux in action and thought I should give it a try.

But why did I, before this, not consider using either? What held me back? Well, I suppose, like many folks, I was thinking along the line of:

  1. It’s hard to learn and has an awkward UX. There are so many cryptic shortcuts and I won’t remember most of them.
  2. It’s only for ops. I don’t need it when developing and writing stuff.
  3. It’s only for working on remote systems. If I don’t ssh into a box I don’t need it.

So 1. is kinda true, not gonna lie. Suck it up and thank me later. Took me a few month to have the muscle memory in place.

And 2. and 3., well, turns out I was so wrong. I do most of my work local (kubectl exec doesn’t count, right?) and I’m so much more productive thanks to tmux.


A few tips and my setup follow.

Tip 1: use the plugin manager

When extending and customizing tmux, you want to do that in a convenient way. So, use the tmux plugin manager (tpm). Think of it like the brew of tmux.

Tip 2: use a plugin that manages state

You don’t want to set up all your projects and the state every time you have to restart the terminal, right? So, use plugins like tmux-continuum and tmux-resurrect that store info like sessions and allow you to restore it with one command.

Tip 3: redefine modifier key on macOS

If you’re using macOS, redefine the Caps Lock key to CTRL like so:

tmux overview

This makes for a much smoother shortcut, if you also change the trigger to CTRL+A.

Tip 4: redefine shortcuts

To make it easier to remember shortcuts, redefine them to stuff that’s easier to remember. For example, if I want to split a pane vertically, I use trigger+| which looks much more like a vertical split and hence is easier to remember than trigger+". Same for horizontal split: I’m using - which defo reminds me of horizontal. Much more than the default % does. Seriously? Like, why?

Example: my setup

All the above tips implemented and a few more things like themes, shortcuts for applying config changes, and getting most out of the status bar at the bottom—here’s my setup, that is, the content of my ~/.tmux.conf:

# Change trigger from CTRL+b to CTRL+a
unbind C-b
set -g prefix C-a

# Ensure that we can send Ctrl-A to other apps
bind C-a send-prefix

# Reload the file with trigger+r
bind r source-file ~/.tmux.conf \; display "tmux config reloaded :)"

# Splitting panes with | and -
bind | split-window -h
bind - split-window -v

# When splitting panes retain current directory of existing pane
bind _ split-window -v -c "#{pane_current_path}"
bind \ split-window -h -c "#{pane_current_path}"

# Source ~/.bashrc with trigger+b
bind b send-keys "source ~/.bashrc" "Enter" \; display ".bashrc sourced :)"

# No delays
set -s escape-time 1

# Enable mouse selections
set-option -g mouse on

# Set base index for windows to 1 instead of 0
set -g base-index 1
# Set base index for panes to 1 instead of 0
setw -g pane-base-index 1

# Set the default terminal mode to 256color mode
set -g default-terminal "screen-256color"

# Theme
set -g status-bg colour231
set -g status-fg colour27
set -g status-right-length 120
set -g status-left-length 50
set -g window-status-current-bg colour231
set -g window-status-current-fg colour27
setw -g window-style fg=colour240,bg=colour235
setw -g window-active-style fg=white,bg=black
set -g pane-border-bg black
set -g pane-border-fg colour238
set -g pane-active-border-bg black
set -g pane-active-border-fg colour27

# Center the window list in the status line
set -g status-justify centre

# Left status: session | battery | date and time
set -g status-left " #[bold]#S #[fg=black]| #{battery_percentage} | %FT%H:%M"

# Right status: Kubernetes context, see
# and AWS context, see
set -g status-right "#(bash ~/.tmux/aws-tmux/aws.tmux)"

# Resurrect, see
# Restore sessions trigger + CTRL-s (safe) / CTRL-r (restore)
set -g @plugin 'tmux-plugins/tmux-resurrect'

# tmux-continuum, see
# saves/restores state automatically every 15min interval
set -g @plugin 'tmux-plugins/tmux-continuum'
set -g @continuum-restore 'on'

# battery, see
set -g @plugin 'tmux-plugins/tmux-battery'

# The tmux plugin manager, see
run '~/.tmux/plugins/tpm/tpm'

I hope this post motivated you a little to have a look at tmux and maybe give it a try. With above tips applied, it shouldn’t be too painful to set up and get started.

Happy tmux-ing!