Every time I reopen tmux, some of the settings in my .tmux.conf are reset, and I have to run tmux source-file ~/.tmux.conf
to reapply them. Oddly, some settings are not reset.
For example, these survive across tmux sessions:
# Use | and - for splitting windows
bind-key | split-window -h
bind-key - split-window -v
These reset every session:
# Change default 'prefix' key to '`'
set prefix `
unbind-key C-b
bind-key ` send-prefix
Why the difference in behavior?
And is there a way to automatically reload .tmux.conf whenever a tmux session starts?
set -g prefix `
Stops those commands from resetting.
Automatically reloading them is unnecessary if they don't reset, and the ones that reset here are the set-prefix
(or "set-option") block because set-option is sensitive to "session mode". Without -g
, set-option defaults to session mode. But since there's initially no tmux session to apply itself to, it doesn't work until .tmux.conf is re-sourced while in a new tmux session. From the man
page,
If -g is given, the global session or window option is set.
Setting it instead to the global session pre-applies the command to all new tmux sessions.