How to source tmux config file?

Quick Answer

To reload your tmux configuration without restarting, use: tmux source-file ~/.tmux.conf from the command line, or from within tmux: Ctrl+b : source-file ~/.tmux.conf

tmux source-file ~/.tmux.conf

Detailed Explanation

After making changes to your tmux configuration file, you need to reload it for the changes to take effect. This can be done without restarting tmux or losing your current sessions and windows.

Method 1: From outside tmux

If you're not currently inside a tmux session, you can reload the configuration using:

$ tmux source-file ~/.tmux.conf

This will apply the configuration to all running sessions.

Method 2: From within tmux

If you're already inside a tmux session:

  1. Press Ctrl+b to activate the prefix
  2. Press : to enter command mode
  3. Type source-file ~/.tmux.conf and press Enter
Ctrl+b :source-file ~/.tmux.conf

Method 3: Create a reload binding

For convenience, add a custom key binding to reload your config. Add this line to your ~/.tmux.conf:

# Add binding to reload tmux.conf with prefix-r
bind r source-file ~/.tmux.conf \; display "Config reloaded!"

With this binding, you can reload your configuration by pressing Ctrl+b r. The \; display "Config reloaded!" part shows a confirmation message in the tmux status line.

Verifying that your changes were applied:

After reloading the configuration, you can verify that your changes were applied:

Ctrl+b :show-options -g

This shows global options. You can also check window-specific options:

Ctrl+b :show-window-options -g

Pro Tip

If some changes don't take effect immediately, especially those related to key bindings or layouts, you might need to restart the tmux server:

# Save your sessions first
$ tmux kill-server
$ tmux

Alternatively, use the tmux-resurrect plugin to save and restore your sessions before restarting the server.

Troubleshooting

If you see error messages when reloading, check for syntax errors in your config file:

# Validate tmux.conf syntax
$ tmux -f ~/.tmux.conf new-session -d
$ echo $?
# If exit code is 0, the syntax is valid

Fix any syntax errors in your config file, then try sourcing it again.