 davelab
 GitHub

Tmux Configuration

Overview

You can copy the provided configuration file to ~/.tmux.conf or ~/.config/tmux/tmux.conf and use it directly. It’s a pretty standard configuration and it’s short enough that we can walk through the whole thing, and you can change it to your taste.

Start by sourcing the Example tmux.conf into your current session:

  1. Copy the example config file to ~/.tmux.conf (or ~/.config/tmux/tmux.conf).
  2. In your open session, execute C-b : to bring up the command prompt.
  3. Type source-file ~/.tmux.conf and press Enter/Return to activate that configuration.

This config changes the prefix to C-a. Keep that in mind as you continue so you can translate any examples to the correct sequence.

The first customization I always make is to re-bind the prefix key. By default, it’s C-b (Ctrl+b).

You may like to re-bind the prefix to something like C-a or even “`” (backtick).

unbind C-b
set -g prefix C-a
bind C-a send-prefix

Using C-a is a little more comfortable, doesn’t typically conflict with other common keybindings, and matches the prefix idiom used by gnu-screen.

The idea behind using “`” was that it was a single-key prefix, which makes it easy to type, and it’s rarely typed in day-to-day work. If you do need to use it, you can hit “`” twice in a row. However, I find myself writing a lot more markdown with code sections, or other applications where I actually need to use “`”. So I typically use C-a myself.

I also like to bind a key to source the configuration file to apply recent changes:

unbind r
bind r source-file ~/.config/tmux/tmux.conf

I disable support for mouse selection and input, set the clock to 24-hour format, and set a large history limit. You may want to customize these:

set  -g mouse             off
setw -g clock-mode-style  24
set  -g history-limit     50000

Status Line

The tmux status-line shows a list of active windows in your session, and indicates which one is selected.

It can also be configured to show useful information about your command, session, or system environment.

set -g status-style bg='#111111',fg='#676E7D'
set -g status-interval 1
set -g status-left '[#{session_name}] '
set -g status-right '%Y-%m-%d %T %A'
set-option -g status-position bottom

image

Format String

If you’ve ever configured a prompt-string for your shell, then you know how this works. Of course, tmux has it’s own system and syntax, different from that of zsh. But, just like configuring your zsh prompt, you probably only need to do it one time, and it’s not actually very hard.

You still supply a format-string, and certain characters and escape sequences will be replaced when the status line is rendered.

Reference manual

Show current date and day of the week, in a blue color:

set -g status-right '#[fg=#4EA1FF]%Y-%m-%d %T %A'
# you might need to make the section max-width to make room
set -g status-right-length 40

Show the name of the current session (#S), the number of clients connected to the session in parentheses, in blue text. And show a magnifying glass on the left when zoom mode is active:

set -g status-left '#[fg=#4EA1FF]#{?window_zoomed_flag,🔍,}[#S(#{session_attached})]'
# you might need to make the section max-width to make room
set -g status-right-length 20

image

The default styles and colors are set by the status-style option. When you use #{default} to reset styles, this is what it will use as the default.

You can also set a different style for the active session “tab” on the status line with window-status-current-style.

set-option -g window-status-current-style fg=#BD5EFF

image

tmux-send-keys

You can run a command from one shell, and have tmux type the arguments into another pane.

This is a cool trick and can be very useful for scripting or making custom keybindings to coordinate things between multiple panes.

  1. Make sure you have at least one vertical split on your open window (prefix ").
  2. Navigate to the top pane with prefix ↑.
  3. Type the following command at the terminal:
tmux send-keys -t {down-of} "ls -al" Enter

image

Plugins and Alternatives

There are plugins for tmux, and even plugin managers. I’ve never used a tmux plugin myself but, if you are interested, here is a list.

There are a few alternatives to tmux that are worth mentioning:

References:


HOME