17.7 tmux Key Bindings and .tmux.conf Configuration
Right, let’s talk about the part of tmux that will make you feel like a wizard instead of a button-masher: key bindings and the .tmux.conf file. This is where you stop fighting the defaults and start bending tmux to your will. The out-of-the-box key bindings are… fine. For a 1990s text editor. The prefix key (Ctrl-b by default) is the main culprit. It’s a pinky-stretching, RSI-inducing abomination that was clearly chosen by someone who has never had to type Ctrl-b a hundred times in an hour. We’ll fix that first.
Your .tmux.conf file, living in your home directory (~/.tmux.conf), is your control panel. This is a simple text file where you redefine keys, set options, and generally tell tmux how to behave. When you first create it, it does nothing. tmux won’t automatically reload it either; you have to tell it to. You can either restart your server (all your sessions, windows, and panes—brutal) or, from inside tmux, type Ctrl-b then : to get the command prompt, and enter source-file ~/.tmux.conf. This reloads the config live. Do this every time you make a change. You’ll do it so often you’ll bind that to a key, too.
The First Order of Business: Dethroning Ctrl-b
We are changing the prefix. This is non-negotiable. The most popular replacement, and my strong recommendation, is Ctrl-a. It’s right next to the caps lock key (which you’ve hopefully remapped to Ctrl already, because you’re not a savage), making it a effortless thumb-pinky combo. It’s also the “beginning of line” key in bash, which is a happy coincidence.
# ~/.tmux.conf
# Set the prefix to Ctrl-a, unbind the default Ctrl-b
unbind C-b
set-option -g prefix C-a
bind-key C-a send-prefix
That last line, bind-key C-a send-prefix, is a brilliant little trick. It means if you hit Ctrl-a twice, it will send a literal Ctrl-a to whatever program is running in your pane (e.g., to jump to the start of the line in bash). You get the new prefix and keep the original functionality. It’s a two-for-one deal.
Making Panes Less Maddening
The default keys for splitting panes are logical if you’re a machine: % for vertical and " for horizontal. I am not a machine. I have to look down at the shift key to remember which is which. Let’s change them to something human.
# More intuitive split keys. | for vertical, - for horizontal.
unbind '"'
unbind %
bind | split-window -h -c "#{pane_current_path}"
bind - split-window -v -c "#{pane_current_path}"
See that -c "#{pane_current_path}" part? That’s the pro move. By default, when you split a pane, the new pane starts in whatever directory the tmux server was launched from (usually your home directory). This option tells it to instead start in the current working directory of the pane you’re splitting. No more cding around just to get to where you already are. This is a quality-of-life upgrade so significant it should be the default.
Vi Keys for Copy Mode, Because You’re Not a Monster
The default for moving around in copy mode (the scrollback buffer) is emacs keys. Even if you use emacs, this is cruel and unusual punishment. Let’s switch to vi keys for navigation. It’s objectively better for moving around a buffer of text.
# Use vi keys in copy mode
setw -g mode-keys vi
# Also, make mouse interactions less terrible (optional but recommended)
set -g mouse on
Now, when you enter copy mode (Ctrl-a [), you can use h, j, k, l to move, v to start a visual selection, y to yank (copy) your selection. To paste, it’s Ctrl-a ]. This is lightyears better.
The Golden Rule: Reloading Your Config Easily
You’re going to be changing this file a lot. Typing out that source command is for chumps. Bind it to something easy.
# Reload the config file with Ctrl-a r
bind r source-file ~/.tmux.conf \; display-message "Config reloaded!"
Now, after you edit ~/.tmux.conf, just hit Ctrl-a r. The display-message part is a nice touch that prints a confirmation at the bottom of the screen so you know it worked.
A Note on the “Gotchas”
Be warned: tmux has a… unique configuration syntax. The space between an option and its value is critical. set -g mouse on works. set -g mouseon does absolutely nothing and will leave you screaming at your unresponsive mouse support. Also, changes only affect new sessions and panes by default. If you change a window option (setw) and want it to apply to an existing window, you’re out of luck. This is why you get good at that reload key binding.
The goal here isn’t to memorize a list of commands, but to understand that .tmux.conf is your lever to move the world. You start by changing the prefix, then you fix the annoyances one by one. Every time you think “I wish it did this instead,” you jump into the config and make it so. That’s the power move.