Video

Want to see the full-length video right now for free?

Sign In with GitHub for Free Access

Notes

Configuration

Configuration Interfaces

Tmux has 3 interfaces for running commands and making configurations:

  1. Tmux executable - This is the tmux command available in your shell. All commands can be run directly against this, but note that any configurations set via the tmux command will be cleared when the server is shut down.
  2. Tmux command prompt - The command prompt allows you to run all the same commands as can be run against the executable but has the benefit that you can interact with it even when a process is occupying the full screen, such as Vim would. The command prompt can be accessed by running <prefix>: and will temporarily take over the tmux status bar. Note, there is no need to type tmux before a command when in the command prompt. Also, just like with the executable, any configurations made will be cleared when the server is shut down.
  3. .tmux.conf file - The final (and primary) method for configuring tmux, this file lives in your home directory and is read by tmux when the server first starts up (when you start your first session). The configuration syntax is identical to what you run against the executable or in the command prompt, so both can be used to test out commands and configurations prior to adding them to your .tmux.conf. This file will be read every time the server starts up but will not be read when opening new windows, panes, or sessions after the server starts. See below for how to reload the config file manually.

Reloading the Config File Manually

Add the following to your .tmux.conf to allow for reloading your .tmux.conf. This allows for rapid iteration on your configuration and making sure any updates you make to your tmux configuration will persist for future sessions.

bind-key r source-file ~/.tmux.conf \; display-message "~/.tmux.conf reloaded"

Advanced Key-Binding

By default, all tmux key-bindings will require you to type the prefix key sequence first, then the desired key to activate the binding. There are two flags that can be used to circumvent the prefix key:

  • -n - This flag allows the key-binding to run without need for the prefix key. Note, since tmux wraps all terminal interaction, setting any key-binding with the -n flag will essentially prevent you from sending that sequence through to underlying processes such as Vim since tmux will catch the key sequence and act on it.
  • -r - This flag allows key-bindings to be repeated without requiring the prefix key.

Status Bar

The status-right option configures the text displayed on the right side of the tmux status bar and configured with a combination of:

  • Literal text - Use to space out or wrap other output.
  • Tmux format patterns - Special patterns such as #S for the session name will be replaced with the corresponding value. See the FORMATS section of the tmux man page for more options.
  • Shell commands - Any shell command can be included in the format string, wrapped in #(...), and it will be replaced with its output.

Battery Command

The battery command used in the tmux prompt comes from Nicolas Goles's battery script, which can be installed via homebrew.

Final Configuration

The .tmux.conf as of the end of step 2:

unbind C-b
set -g prefix C-s
bind-key -r C-s send-prefix

bind-key r source-file ~/.tmux.conf \; display-message "~/.tmux.conf reloaded"

bind-key -n C-h select-pane -L
bind-key -n C-j select-pane -D
bind-key -n C-k select-pane -U
bind-key -n C-l select-pane -R

set-option -g default-terminal "screen-256color"
set-option -g status-keys "emacs"

set-option -g status-bg '#666666'
set-option -g status-fg '#aaaaaa'

set-option -g status-left-length 50

set-option -g status-right " #(battery -t)  #(date '+%a, %b %d - %I:%M') "