To change the tmux prefix key from the default Ctrl+b, add these lines to your ~/.tmux.conf
file: unbind C-b
to remove the default binding, then set -g prefix C-a
to set a new prefix (in this example, Ctrl+a), and finally bind-key C-a send-prefix
to allow sending the prefix to nested tmux sessions. After saving, reload your configuration with Ctrl+b : source-file ~/.tmux.conf
or restart tmux.
# Add to ~/.tmux.conf unbind C-b set -g prefix C-a bind-key C-a send-prefix
The prefix key in tmux is the key combination you press before entering any tmux command. By default, this is Ctrl+b, but many users change it for comfort, to avoid conflicts with other programs, or for consistency with GNU Screen (which uses Ctrl+a).
Common reasons to change the default prefix:
To change your prefix key, follow these steps:
1. Edit your tmux configuration file:
# Open ~/.tmux.conf in your preferred editor vim ~/.tmux.conf # or nano ~/.tmux.conf
2. Add the configuration lines:
# Remove the default prefix unbind C-b # Set new prefix key (Ctrl+a in this example) set -g prefix C-a # Allow sending the prefix key to applications by pressing it twice bind-key C-a send-prefix
The third line is particularly important if you need to send the actual Ctrl+a keystroke to applications inside tmux. With this binding, you can press Ctrl+a twice to send one Ctrl+a to the current program.
3. Apply the changes:
# If tmux is already running, reload the configuration # First press Ctrl+b (the old prefix), then type :source-file ~/.tmux.conf Ctrl+b :source-file ~/.tmux.conf # Or restart tmux tmux kill-server tmux
After reloading, your new prefix key will be active. Remember to use the new prefix for all tmux commands going forward.
Here are some common alternatives to the default Ctrl+b prefix:
If you want to use a single key like backtick (`) as your prefix:
# Set backtick as the prefix unbind C-b set -g prefix ` bind-key ` send-prefix # Optional: Use a key like F12 as an alternative prefix set -g prefix2 F12 bind-key F12 send-prefix -2
When using a character key as prefix, you'll need to press it twice to send it to applications.
If you frequently work with nested tmux sessions (tmux inside tmux), consider using different prefix keys for each level:
# For your local ~/.tmux.conf set -g prefix C-a # For the remote ~/.tmux.conf set -g prefix C-b # Keep the default on remote servers
This helps avoid confusion about which tmux session you're sending commands to.