tmux-configuration

2021-01-23

 | 

~3 min read

 | 

469 words

In Tmux: Getting Started, I walked through some of the basics of using tmux, but didn’t cover how to really make it your own. One of tmux’s best attributes is that it can be customized to fit your needs and tastes. But how is that all done?

Customizing Tmux

Similar to vim, bash, zsh, and so many other tools, tmux has a configuration file, .tmux.conf which is often found in the root directory. We can open it with our text editor of choice, for example, with vim, we might do:

% vim ~/.tmux.conf

The configuration syntax reminds me of emacs personally, though as I’m no expert there either, I could be mistaken.

For example, if we want to change the configuration for the prefix binding from the default of C-b to something more ergonomic like C-a, we could add the following to our our .tmux.conf config file:

# Rebinding Prefix key
unbind C-b
set-option -g prefix C-a
bind-key C-a send-prefix

Understanding What’s Available For Customization

To understand the full list of commands that can be configured, look at tmux’s Man Page, under Commands. The default key bindings section will also be useful to understand if something needs to be unbound.

Alternatively, you can look at all the existing key bindings with the list-keys command (C-b :, then list-keys, or lsk, in the tmux prompt).

Saving Changes

Once the .tmux.conf file has been saved, we have two options for having these changes take hold:

  1. Kill and restart our tmux session
  2. Source the file (similar to zsh or bash)

To source a file in tmux, enter Command Mode (C-b : by default). Then enter the source-file command:

source-file [-Fnqv] path ...
        (alias: source)
    Execute commands from one or more files specified by path
    (which may be glob(7) patterns).  If -F is present, then
    path is expanded as a format.  If -q is given, no error
    will be returned if path does not exist.  With -n, the file
    is parsed but no commands are executed.  -v shows the
    parsed commands and line numbers if possible.6
:source-file ~/.tmux.conf
Quick Refresh

If you’re planning to make a lot of changes to your .tmux.conf file, or want a faster way to refresh than entering command mode, you can add the following keybinding to the .tmux.conf to make it one key in the future:

# Quick Refresh
bind R source-file ~/.tmux.conf

Now, with a simple prefix and capital R, tmux will fetch its latest configuration file

Wrap Up

If you’re looking to bootstrap your tmux configuration, there are plenty of examples in the community, but armed with the knowledge of this post, you’ll be able to build your own up over time to perfectly suit your tastes.

Onwards!



Hi there and thanks for reading! My name's Stephen. I live in Chicago with my wife, Kate, and dog, Finn. Want more? See about and get in touch!