TMUX

By Vitaly Parnas

Here I divulge a handful of Tmux terminal multiplexor features not readily apparent among novice or even some seasoned users.

Repeat mode

In Tmux, you must by default initiate commands with a prefix key, normally Ctrl-B. For frequently used commands such as pane/window navigation and splitting, it can become cumbersome to precede every shortcut with the prefix combination, especially when you repeat a number of operations repetitively, such as movement across multiple panes or windows.

To ease the burden, Tmux enables the binding of shortcuts in ‘repeat mode’ via the -r flag. In this mode, you can strike the prefix combination once, and follow by successive strokes of just the shortcut keys, provided they proceed maximally within the configurable repeat-time duration:

set-option -g repeat-time 750 # time (in ms) for repeatable (-r bound keys) without the prefix key

bind -r h select-pane -L
bind -r j select-pane -D
bind -r k select-pane -U
bind -r l select-pane -R
bind -r o select-pane -t :.+

bind -r n next-window
bind -r p previous-window
bind -r b last-window
bind-key -r C-o rotate-window

bind -r < resize-pane -L 10
bind -r > resize-pane -R 10
bind -r - resize-pane -D 10
bind -r + resize-pane -U 10

Capture pane contents

The Tmux ‘capture-pane -p’ option, in absence of other parameters, pipes the visible pane contents to standard out. You can thus pipe the console output to another utility.

To open and edit the pane contents in your text editor, first create the following executable somewhere within your path:

‘edit-stdin.sh’ “`sh tmpfile=$(mktemp –tmpdir stdin-edit.XXXXXX) cat > ”$tmpfile"

tmux new-window “$EDITOR $tmpfile; rm $tmpfile” “`

Then bind the operation to the key of your choosing:

bind-key e run-shell "tmux capture-pane -p | edit-stdin.sh"

Pop-up persistent terminals

This enables you to launch a named Tmux session if not already present, or otherwise attach to an existent. It also detaches any other attached client.

This is especially handy as a macro for launching persistent terminals of embedded CLI applications (ie VIM, emacs, text-based web browser, music player, etc).

tmux new-session -AD -s \<name\> [cmd]

Example:

alias pop_up_notepad="$TERMINAL -e tmux new-session -AD -s Notes 'vim ~/.notes'"

Move window

Move one Tmux window to another within the same or between different sessions. You may specify the <window-id> via a window index or name, substring including.

To specify the window and session, provide <session>:<window> for the window identifier. If source or target not specified, assumes the current window.

tmux move-window [-t target-window]

Misc

bind B set-option status # toggle the status bar
# Use a plain white text, black background status bar style to 'blend in' with rest of terminal
set -g status-style "fg=white"
bind R source-file ~/.tmux.conf # Reload the config

Questions, comments? Connect.