learntmux.dev
LEVEL 4 · CONFIGURE

Your .tmux.conf, a new prefix, key bindings, status line, vi keys.

Write a tmux.conf you actually understand: set options, rebind the prefix, add your own key bindings, and style the status line.

11 tasks · about 52 minutes · 26 key bindings

Start with task 1
  1. 01

    Show, set and unset options

    4 min

    Read option values of each type, set a server option and a session option, watch renumbering happen, and unset one back to its default.

    :show -g option:set -g option value:set -gu option
  2. 02

    Write the configuration file

    4 min

    Create ~/.tmux.conf, load it into the running server, then restart the server to see it load by itself.

    :echo 'set -g mouse on' >> ~/.tmux.conf:source ~/.tmux.conf
  3. 03

    Add and remove key bindings

    5 min

    Bind a key to jump to window 10, bind two keys to split panes, bind a key that skips the prefix, then remove a binding.

    :bind M-0 selectw -t:=10:bind -n M-n next-window:unbind M-0
  4. 04

    Change the prefix key

    4 min

    Move the prefix to C-a in the configuration file, unbind C-b, and make C-a C-a send the key through.

    :set -g prefix C-a:bind C-a send-prefix
  5. 05

    Customize the status line

    4 min

    Move the status line to the top, colour it, and simplify the right side to the time.

    :set -g status-position top:set -g status-style bg=red:set -g status-right '%H:%M'
  6. 06

    Formats and embedded styles

    4 min

    Rebuild status-left with a format variable, an embedded style and a conditional that lights up when the prefix is pressed.

    :set -g status-left '#{session_name}':#[fg=red]:set -g status-left-length 40
  7. 07

    Embedded shell commands

    3 min

    Show the output of a shell command in the status line and control how often it refreshes.

    :set -g status-right '#(cmd)':set -g status-interval 5
  8. 08

    Configure the pane border

    4 min

    Colour the pane borders, highlight the active one, and give every pane a bold title bar.

    :set -g pane-border-style fg=red:set -g pane-active-border-style 'fg=red,bg=yellow':set -g pane-border-status top
  9. 09

    Use vi keys in copy mode

    4 min

    Switch copy mode and the prompt to vi keys, rebind v to start a selection, and copy a line the vi way.

    :set -g mode-keys vi:bind -T copy-mode-vi v send -X begin-selectionEnter
  10. 10

    Mouse copying behaviour

    4 min

    Change what happens when a mouse drag ends so the selection stays visible after it is copied.

    :bind -Tcopy-mode MouseDragEnd1Pane send -X copy-selection-no-clear:unbind -Tcopy-mode MouseDragEnd1Pane
  11. 11

    Challenge: write your own tmux.conf

    challenge12 min

    Author a complete configuration file from scratch and prove it loads on a freshly started server.