Overview

So if you’ve used GNU Screen and liked it, I think you’ll love tmux. It’s basically GNU screen on steriods.

It all started when I wanted to split a terminal window into two sub-terminal windows, similar to how vim can split the terminal window to display multiple buffers.

Now that widescreen monitors are a thing (yes, I just dated myself), the best way to divide a screen is vertically. Unfortunately, GNU screen doesn’t support this with the release that comes with most distros unless you patch it. Furthermore, screen just looks kinda disgusting when it does a split.

Some googling quickly pointed me to tmux, which is pretty gosh-durned awesome.

I’ve only scratched the surface of its features, but I had some trouble getting my ~/.tmux.conf all set up the way I wanted, so I thought I’d write it up.

I found the following writeup from HawkHost super helpful as well:

Escape Key

GNU screen defaults its escape key to CTRL-a, and tmux defaults to CTRL-b. I personally prefer the backtick or ` key, because it gets away from command sequences I use a lot that involve the CTRL key.

However, the backtick key shows up a lot in scripting, so we’ll need to be able to switch back and forth between backtick and CTRL-b.

We can use the escape key plus F11 and F12 to switch back and forth with the following ~/.tmux.conf lines:

Configure Escape Key
# command prefix (like screen)
unbind C-b
set-option -g prefix `
bind-key F11 set-option -g prefix C-b
bind-key F12 set-option -g prefix `

So to switch to CTRL-b, you’d hit the following:

` F11

To switch back, you’d use

CTRL-b F12

Status Bar

One of tmux’s cool features is you can add a status bar to the bottom. I’ve chosen to display user@hostname on the left, and the load averages then date/time on the right.

Configure Status Bar
# Set status bar
set -g status-bg black
set -g status-fg white
set -g status-interval 30
set -g status-left-length 30
set -g status-left '#(whoami)@#(hostname -s)'
set -g status-right '#(cut -d " " -f 1-3 /proc/loadavg) %y-%m-%d %H:%M' 1
set-window-option -g window-status-current-bg white
set-window-option -g window-status-current-fg black
setw -g automatic-rename
1 This line must be set -g status-right #(uptime | cut -d ': -f4) %y-%m-%d %H:%M' in OSX.

Panes

Pane Coloring

If your version of tmux supports it, you can make your pane dividers look nice:

Beautifying tmux Panes
# Set pane divider
set -g pane-border-bg black
set -g pane-border-fg white
set -g pane-active-border-bg black
set -g pane-active-border-fg white

Pane Hotkeys

So, using the " key to make new panes is really annoying because it defaults to horizontal. In order to fix that, we can remap the pipe (|) and dash (-) keys to split the window vertically and horizontally if you want.

Pane Hotkey Mappings
# Set pane hotkeys
unbind %
bind-key | split-window -h
bind-key - split-window -v

Navigating Panes

The fastest way to navigate between panes is using the q hotkey. Doing so displays a number on each pane. Pressing the appropriate number on the keyboard will send you to the appropiate pane.

This is much better than navigating using the o hotkey for the next pane.

So tmux includes a link-window command, which is like a symlink for windows. Every time you make a change to a window, it’s reflected on the linked window. This holds true for windows in different sessions.

Unfortunately, as of 11-07-27, there is no link-pane command:

To work around this, we can use GNU screen!

In the source pane, run a new instance of screen. Then, in the pane you want to link to the source pane, run screen -x, which will open the screen session.

Credit goes to Saugata Ghose for asking about this feature in tmux, and for the following Unix adventure to figure out the workaround.