Using tmux as a Terminal Multiplexer

tmux lets me keep manage multiple command line windows and shells inside a single terminal window. That's fine in its own right, but the thing I really appreciate about tmux is it lets me leave long-running commands going in the background without worrying about nohup or accidentally closing a background window.

I don't start tmux by default, since I like occasionally starting a quick temporary terminal on a different window. But I can always access my tmux session quickly with an alias in my ~/.profiletmux allows you to have multiple named sessions, which can be useful in shared environments, or when it's being used for very long-running processes. But I prefer to just use it with a single session, and the alias provided will jump you directly into a single running session.:

alias tmuxs='tmux attach || tmux new-session'

I use the following config file (~/.tmux.conf):

# I use zsh by default
set-option -g default-shell /bin/zsh

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

# Use C-z instead of C-b (personal preference)
unbind C-b
set -g prefix C-z
bind C-z last-window
bind z send-prefix

set -g mouse on
set -g history-limit 250000
setw -g alternate-screen on

# Lower the escape timing from 500ms to 50ms for quicker response to scroll-buffer access.
set -s escape-time 50

# Use | and - for horizontal/vertical window splitting
unbind %
bind | split-window -h
bind - split-window -v

# Refresh config with r
bind-key r source-file ~/.tmux.conf \; display-message "~/.tmux.conf reloaded"

# Fix titlebar
set -g set-titles on

# VIM mode
set -g mode-keys vi

# Avoid date/time taking up space
set -g status-right ''
set -g status-right-length 0

With that config, I mostly use the following commands to move around:

ctrl-z is the prefix key, used in combination with another key sequence to perform an action.

ctrl-z up/down/left/right arrow change the current pane based on the direction.

ctrl-z 0-9 change the current window based on the number.

ctrl-z - splits the screen vertically, creating a new pane.

ctrl-z | splits the screen horizontally, creating a new pane.

ctrl-z x closes the current pane.

ctrl-z c creates a new window.