Reload of tmux config not unbinding keys (bind-key is cumulative)

keyboard shortcutstmux

I've been experimenting with different tmux keybinding settings and I've noticed the following:

If I reload my tmux config (from within tmux) the keybindings I once had loaded will remain loaded. The only way (I know of) to clean this up is to quit all tmux sessions and restart. So it looks like tmux remembers all previously loaded keybindings and will only remove them on a fresh start or by explicitly unbinding them.

To recreate this:

  • open a terminal (A)
  • start tmux
  • check whether the keybinding shows a clock (press PREFIX C-t)
  • press PREFIX ? to see the keybinding in the list
  • edit ~/.tmux.conf
  • add a keybinding (bind C-t display "Keybinding C-t")
  • reload tmux config (PREFIX : source-file ~/.tmux.conf)
  • check whether the keybinding works (press PREFIX C-t)
  • press PREFIX ? to see the new keybinding in the list
  • edit ~/.tmux.conf again
  • remove the keybinding (so remove bind C-t display "Keybinding C-t")
  • reload tmux config (PREFIX : source-file ~/.tmux.conf)
  • check whether the keybinding works (press PREFIX C-t), it still displays "Keybinding C-t"
  • press PREFIX ? to see that the new keybinding is still in the list
  • exit tmux
  • enter tmux
  • check whether the original keybinding works again (press PREFIX C-t), it should now display a clock again
  • press PREFIX ? to see that the new keybinding has been removed from the list

My question: is there a way to instruct tmux to "forget" all loaded configs and then load .tmux.conf ?

Best Answer

According to the tmux(1) man page, unbind-key -a is what you are looking for.

Note that tmux runs a server that will only exit once all sessions are closed, and the key-bindings are per-server. Hence once you create a binding, it will be persistent over all client detaches.

That said, put unbind-key -a at the very top of your configuration file, and on config reload it should do what you want - unbind everything and start binding from scratch. Or - if your modifications are smaller - unbind only what you want to change.

Related Question