tmux – How to Reload tmux Config Correctly

tmux

According to the man page, if I run this command:

tmux source-file ~/.tmux.conf

tmux is going to execute the commands in ~/.tmux.conf. However if, for example, I add a key binding to tmux.conf, and later remove it, the key binding stays, even if I source the file (which is logical, since there's no actual command to execute for that binding).

So I'm wondering, before sourcing the config, if there a way to somehow clear tmux's internal state (all binding, settings, etc.) so that it starts with the default one?

Best Answer

Changing the tmux configuration and rereading it in an existing tmux session will only change the settings that the configuration file explicitly changes. Removing a key binding from the configuration file, for example, will not unbind that key when you reload the configuration unless you also explicitly unbind it in the configuration.

This is similar to sourcing a shell script with a variable assignment in it; You source it once, which sets the variable, and then you remove it from the file and source it again. This will not remove the shell variable.

The simplest way to reread the configuration file from scratch is to exit tmux and restart it. tmux will exit as soon as all its sessions have ended, which will happen if you, for example, exit all shell sessions from within tmux. You may also issue the tmux command kill-server from within tmux to kill the tmux server and all sessions.

Related Question