ruk·si

tmux

Updated at 2025-08-26 02:54

tmux is a terminal multiplexer that allows easily running multiple applications in the same terminal and keeping everything as a detached process.

Very similar to GNU Screen if you have used that before.

What I do is I simply have tmux starting command in .bashrc. This has added benefit that most IDEs that offer terminals will also start tmux automatically.

# automagical tmux if not already in a tmux session
if command -v tmux &> /dev/null && [ -z "$TMUX" ]; then
    tmux attach-session -t default || tmux new-session -s default
fi

tmux is especially useful when connecting to remote hosts and want to keep processes running after disconnecting.

cltr+b, d   # detach from the tmux session, leaving it running
tmux attach # attach back to tmux session

You start, attach to and detach from tmux sessions. A single machine can have many tmux sessions running.

Sessions            (current session shown bottom left in [brackets])
    > Windows       (windows are shown in bottom bar, current marked with *)
        > Panes     (tiled sections of a window, active highlighted with green)

I mostly vanilla tmux keybindings for easier cross-system usage, but most people like to change the default prefix key from ctrl+b to ctrl+a as ctrl+b is tedious to press.

My ~/.tmux.conf config is rather minimalistic:

# the default is emacs, but if $EDITOR is set to vim, it will default to vi
# set -g mode-keys vim

# start window and pane numbering at 1, not 0
set -g base-index 1
setw -g pane-base-index 1

# disable delay that tmux waits for "escape keys" to determine if it's 
# a tmux keybinding, defaults to 500 (ms) but then pressing esc to 
# change modes on vim takes forever...
set -sg escape-time 0

Remember to reload the config after changes with:

# ctrl+b, :
source-file ~/.tmux.conf

Basic keybindings:

  • tmux Start default tmux session.
  • ctrl+b, c Create a new window with a single pane.
  • ctrl+b, 0-9 Jump to a specific window.
  • ctrl+b, " Split pane horizontally.
  • ctrl+b, % Split pane vertically.
  • ctrl+b, arrows Select another pane.
  • ctrl+b, ctrl+arrows Resize selected pane.
  • ctrl+b, z Maximize/normalize selected pane.
  • ctrl+b, x Close the current pane, or window if it's the last pane.

Pane juggling keybindings:

  • ctrl+b, space Cycle through pane layouts.
  • ctrl+b, ! Move current pane to a new dedicated window.
  • ctrl+b, :, join-pane -s 1 Move window 1 to current window.
  • you can also move panes and windows between sessions with join-pane -s [session_name]:[window].[pane]
  • -t allows you to select the window to join to if not the current one

Session keybindings:

  • ctrl+d End of Transmission -signal like normal, closes active pane.
  • ctrl+b, d Detach from the session, leaving it running in the background.
  • tmux attach Attach back to detached tmux session

Browsing keybindings:

  • ctrl+b, [ Enter copy mode for copy-paste, browsing and such.
  • ctrl+b, [, ? Search up in terminal, n for next, N for previous.
  • ctrl+b, [, / Search down in terminal, n for next, N for previous.
  • ctrl+b, [, navigate-with-vim, space, navigate-with-vim, enter Copy to tmux clipboard.
  • ctrl+b, ] Paste from tmux clipboard.
  • ctrl+b, :, capture-pane Copy the visible pane text to tmux clipboard.
  • you can also save it to a file with capture-pane; save-buffer buffer.txt
  • you can explore clipboard with list-buffers and choose-buffer

You can use tmux for automation, but I use rusmux for that. Many people use tmuxinator but I don't like the idea of installing Ruby just for that.

# sends the command to specific session:window.pane
tmux send-keys -t default:1.2 'cd ~/Projects/my-thing' C-m

Sources

  • tmux - Productive Mouse-Free Development, Brian P. Hogan