A few lines of config fix tmux's awkward defaults and make it pleasant to use every day.
tmux reads ~/.tmux.conf at server start (or ~/.config/tmux/tmux.conf, supported since 3.1). The file is just a list of tmux commands, one per line.
Options are set with set: -g sets the global (default) value, -s server options, -w window options (setw is shorthand). Examples: set -g mouse on, set -g base-index 1, setw -g pane-base-index 1, set -g history-limit 50000, setw -g mode-keys vi.
Key bindings are made with bind key command (into the prefix table) and removed with unbind. bind -n binds a key in the root table, without the prefix, so use it sparingly. bind -r makes a binding repeatable: after the prefix you can press it several times.
Two edits nearly everyone makes:
- Split in the current directory:
bind '"' split-window -c "#{pane_current_path}", and the same for%with-h. - A reload binding:
bind r source-file ~/.tmux.conf \; display "reloaded". The\;separates two commands.
Changing the prefix to Ctrl-a: unbind C-b, set -g prefix C-a, bind C-a send-prefix (so C-a C-a sends a real Ctrl-a to the shell).
The config only runs when the server starts. After editing, run tmux source-file ~/.tmux.conf, or kill the server; detaching and reattaching is not enough.
Example
# ~/.tmux.conf
unbind C-b
set -g prefix C-a
bind C-a send-prefix
set -g mouse on
set -g base-index 1
setw -g pane-base-index 1
setw -g mode-keys vi
set -g history-limit 50000
bind | split-window -h -c "#{pane_current_path}"
bind - split-window -v -c "#{pane_current_path}"
bind -r H resize-pane -L 5
bind r source-file ~/.tmux.conf \; display "config reloaded"Remember
- The config is a list of tmux commands, run at server start
- set -g for options, bind/unbind for keys, bind -r for repeatable keys
- Reload with source-file; reattaching does not re-read it
Watch out for
- Editing the config and reattaching, then wondering why nothing changed; the running server must source it.