just a random image from lorem picsum
This is just a random LoremPicsum image

Essential Tmux Configuration and Plugins for Terminal Productivity

I played around with TMUX a little bit and realized how powerful it is when used to work with multiple terminals. For now, I focused on the basic configurations that you can find all over the place on the internet to make TMUX more convenient. This is a summary of my findings from various resources, that will probably improve my workflow overall.

Resources

How to configure tmux

Configuration files for Tmux can be placed in one of these options:

  1. /etc/tmux.conf: for system-wide configuration
  2. ~/.tmux.conf: for user-specific configuration. This file takes precedence over 3.
  3. $XDG_CONFIG_HOME/tmux/tmux.conf: modern XDG-compliant location. If $XDG_CONFIG_HOME is not set, it defaults to ~/.config/tmux/tmux.conf
  4. Explicitly load a config file from any location with tmux -f /path/to/your/custom.conf

Configure tmux

Change the prefix key

The prefix key is indeed one of the weirdest initial key bindings, set to Ctrl + b. I switched it early on to Ctrl + a, and I have also seen Ctrl + space.

# remap prefix from 'C-b' to 'C-a'
unbind C-b
set-option -g prefix C-a
bind-key C-a send-prefix

Enable mouse control

Even though tmux is built to be used only with the keyboard, sometimes you are lazy or you simply forget the keyboard shortcut. Mouse control allows you to select panes and windows with a click. And the resizing is much more convenient with the mouse than with the keyboard!

# Enable mouse control (clickable windows, panes, resizable panes)
set -g mouse on

Renumber windows starting from 1 (instead of 0)

Numbering windows and panes starting with 0 really doesn’t make sense to me, since ‘0’ is on the other side of the keyboard. So it makes much more sense to me to start at 1, even though I am a programmer.

# Start windows and panes at 1 instead of 0
set -g base-index 1
set -g pane-base-index 1
set-window-option -g pane-base-index 1
set-option -g renumber-windows on

Manage panes more effectively without the prefix key

Managing panes is one of the most common tasks you will do in tmux. You can configure tmux to switch and split panes without needing a prefix key. Additionally, most of the time you will want to keep the current directory when splitting the pane. The additional -c "#{pane_current_path}" will handle that.

# split panes using Alt + h/v. keep current dir
bind -n M-v split-window -h -c "#{pane_current_path}"
bind -n M-h split-window -v -c "#{pane_current_path}"

# switch panes using Alt-arrow without prefix
bind -n M-Left select-pane -L
bind -n M-Right select-pane -R
bind -n M-Up select-pane -U
bind -n M-Down select-pane -D

Split panes and keep the current dir

You will probably also split panes quite frequently.

# split panes. keep current dir
bind h split-window -v -c "#{pane_current_path}"
bind v split-window -h -c "#{pane_current_path}"

Misc

# don't rename windows automatically
set-option -g allow-rename off

Install Plugins

Plugins are best installed with the Tmux Plugin Manager. See the details on GitHub for how to install ‘tpm’ and other plugins.

This site has a great list of available tmux plugins: Tmux Plugins & Tools.

TLDR;

# List of plugins
set -g @plugin 'tmux-plugins/tpm'
set -g @plugin 'tmux-plugins/tmux-sensible'
set -g @plugin 'tmux-plugins/tmux-yank'

# Initialize TMUX plugin manager (keep this line at the very bottom of tmux.conf)
run '~/.tmux/plugins/tpm/tpm'

tmux-plugins/tpm

tmux-plugins/tpm: Tmux Plugin Manager

Makes installation of other plugins easier. Make sure to initialize the tmux plugin manager at the end of your configuration file.

tmux-plugins/tmux-sensible

tmux-plugins/tmux-sensible: basic tmux settings everyone can agree on

I installed it without question, so I didn’t hit any limitations myself. If everyone says this is useful, it must be right 🤔.

Useful shortcuts:

tmux-plugins/tmux-yank

tmux-plugins/tmux-yank: Tmux plugin for copying to system clipboard. Works on OSX, Linux and Cygwin.

Watch this YouTube video to learn how tmux-yank can be used. In this section, he suggests to use the vi mode to copy and paste code from the terminal. This is the configuration used in the video:

# set vi-mode
set-window-option -g mode-keys vi
# keybindings
bind-key -T copy-mode-vi v send-keys -X begin-selection
bind-key -T copy-mode-vi C-v send-keys -X rectangle-toggle
bind-key -T copy-mode-vi y send-keys -X copy-selection-and-cancel

The default keybinding to start yanking is <prefix> + [.