Tmux Terminal Multiplexer Cheatsheet and Configuration Guide

Tmux (terminal multiplexer) is an essential tool for developers and system administrators who work extensively in the terminal. This guide provides a comprehensive reference for tmux usage, including custom keybindings, a complete configuration file, and practical tips for maximizing productivity in terminal environments.

Whether you’re managing multiple server sessions, organizing development workflows, or simply want to improve your terminal efficiency, this cheatsheet covers everything you need to master tmux with a powerful custom configuration.

Custom Keybinding Reference

The following keybindings are based on a custom tmux configuration that prioritizes efficiency and ergonomics. The prefix key has been changed from the default Ctrl+b to Ctrl+Space for easier access.

Core Navigation and Control

KeybindingActionDescription
Ctrl+SpacePrefix keyPrimary command prefix (replaces default Ctrl+b)
Ctrl+sSend pane to targetMove current pane to specified target pane
Ctrl+ArrowSwap panesMove panes around using directional arrows

Prefix-Based Commands

KeybindingActionDescription
prefix + mToggle mouse supportEnable/disable mouse interaction with panes
prefix + sSync panesSynchronize input across all panes in current window
prefix + hSplit horizontallyCreate horizontal pane split (maintains current path)
prefix + vSplit verticallyCreate vertical pane split (maintains current path)
prefix + qKill paneClose the current pane
prefix + rResize modeEnter special mode for resizing panes
prefix + kMovement modeEnter special mode for navigating between panes

Special Modes

Resize Mode (prefix + r)

When in resize mode, use these keys without the prefix:

  • h - Resize pane left (5 units)
  • j - Resize pane down (5 units)
  • k - Resize pane up (5 units)
  • l - Resize pane right (5 units)
  • Enter or Escape - Exit resize mode

Movement Mode (prefix + k)

When in movement mode, use these keys without the prefix:

  • h - Select left pane
  • j - Select pane below
  • k - Select pane above
  • l - Select right pane
  • Enter or Escape - Exit movement mode

Complete Tmux Configuration

The following configuration file provides a comprehensive setup for tmux with custom keybindings, visual enhancements, and productivity features.

# setting prefix to esc+return
unbind C-b
set -g prefix C-Space
bind Space send-prefix
 
# custom keybindings
bind m set -g mouse
bind s setw synchronize-panes
# Function to split windows with the same user
bind h split-window -h -c "#{pane_current_path}"
bind v split-window -v -c "#{pane_current_path}"
bind q kill-pane
 
bind -n C-s command-prompt -p "send pane to (target pane):" "join-pane -t :'%%'"
 
# Special mode for resizing panes
bind r run-shell "tmux display-message 'Entering pane resize mode'; \
                  tmux bind -n h resize-pane -L 5; \
                  tmux bind -n j resize-pane -D 5; \
                  tmux bind -n k resize-pane -U 5; \
                  tmux bind -n l resize-pane -R 5; \
                  tmux bind -n Enter run-shell 'tmux unbind -n h; \
                                                 tmux unbind -n j; \
                                                 tmux unbind -n k; \
                                                 tmux unbind -n l; \
                                                 tmux unbind -n Enter; \
                                                 tmux unbind -n Escape; \
                                                 tmux display-message \"Exited pane resize mode\"'; \
                  tmux bind -n Escape run-shell 'tmux unbind -n h; \
                                                 tmux unbind -n j; \
                                                 tmux unbind -n k; \
                                                 tmux unbind -n l; \
                                                 tmux unbind -n Enter; \
                                                 tmux unbind -n Escape; \
                                                 tmux display-message \"Exited pane resize mode\"';"
 
# Special mode for moving panes
bind k run-shell "tmux display-message 'Entering pane move mode'; \
                  tmux bind -n h select-pane -L; \
                  tmux bind -n j select-pane -D; \
                  tmux bind -n k select-pane -U; \
                  tmux bind -n l select-pane -R; \
                  tmux bind -n Enter run-shell 'tmux unbind -n h; \
                                                 tmux unbind -n j; \
                                                 tmux unbind -n k; \
                                                 tmux unbind -n l; \
                                                 tmux unbind -n Enter; \
                                                 tmux unbind -n Escape; \
                                                 tmux display-message \"Exited pane move mode\"'; \
                  tmux bind -n Escape run-shell 'tmux unbind -n h; \
                                                 tmux unbind -n j; \
                                                 tmux unbind -n k; \
                                                 tmux unbind -n l; \
                                                 tmux unbind -n Enter; \
                                                 tmux unbind -n Escape; \
                                                 tmux display-message \"Exited pane move mode\"';"
 
# Move panes around using Shift + arrow keys
bind -n C-Up swap-pane -U
bind -n C-Down swap-pane -D
bind -n C-Left select-pane -L \; swap-pane -t !
bind -n C-Right select-pane -R \; swap-pane -t !
 
# status line config
set -g status-bg black
set -g status-fg white
set -g status-left "#[fg=green]#H"
set -g status-right "#[fg=yellow]#(date)"
 
# setting some defaults
set -g mouse on
set -g mode-keys vi
set-option -g base-index 1
set-window-option -g pane-base-index 1
 
# Automatically renumber windows when one is closed
set-option -g renumber-windows on

Configuration Breakdown

Prefix Key Modification

The configuration changes the default prefix from Ctrl+b to Ctrl+Space, which is more ergonomic and accessible during long terminal sessions.

Path Preservation

When splitting panes with h (horizontal) or v (vertical), the new pane automatically starts in the same directory as the current pane using #{pane_current_path}.

The configuration introduces two special modes:

  • Resize Mode: Temporarily enables vim-like keys (hjkl) for pane resizing
  • Movement Mode: Temporarily enables vim-like keys for pane navigation

Visual Enhancements

  • Custom status bar with hostname on the left and current date on the right
  • Black background with white text for better contrast
  • Green hostname and yellow date for visual distinction

Productivity Features

  • Mouse support enabled by default
  • Vi-style key bindings for copy mode
  • Window and pane indexing starts at 1 instead of 0
  • Automatic window renumbering when windows are closed

Installation and Setup

Installing the Configuration

  1. Save the configuration as ~/.tmux.conf
  2. Restart tmux or reload the configuration:
    tmux source-file ~/.tmux.conf

Starting Tmux Sessions

# Start a new session
tmux new-session -s mysession
 
# Attach to existing session
tmux attach-session -t mysession
 
# List all sessions
tmux list-sessions

Common Workflows

Development Environment Setup

  1. Create a new tmux session for your project
  2. Split the terminal horizontally for code and terminal
  3. Split the bottom pane vertically for logs and git operations
  4. Use sync panes when running commands across multiple servers

Server Administration

  1. Open multiple panes for different servers
  2. Use pane synchronization for running identical commands
  3. Leverage the pane movement feature to organize your workspace
  4. Keep logs in separate panes for monitoring

Troubleshooting

Configuration Not Loading

  • Ensure the configuration file is saved as ~/.tmux.conf
  • Check file permissions and syntax
  • Manually reload with tmux source-file ~/.tmux.conf

Key Bindings Not Working

  • Verify you’re using the correct prefix key (Ctrl+Space)
  • Check for conflicts with terminal or shell key bindings
  • Test in a fresh tmux session

Visual Issues

  • Ensure your terminal supports the color scheme
  • Check terminal color settings and tmux color configuration
  • Verify font rendering for special characters

Advanced Tips

Session Management

  • Use descriptive session names for different projects
  • Leverage tmux’s session persistence across system reboots
  • Create aliases for frequently used tmux commands

Integration with Other Tools

  • Combine with screen recording tools for documentation
  • Integrate with SSH for remote server management
  • Use with development tools that benefit from persistent sessions

Questions Answered in This Document

Q: How do I change the tmux prefix key from Ctrl+b to something more accessible? A: Add unbind C-b and set -g prefix C-Space to your .tmux.conf file to change the prefix to Ctrl+Space, which is more ergonomic for extended use.

Q: What’s the difference between horizontal and vertical splitting in tmux? A: Horizontal splitting (prefix + h) creates a new pane below the current one, while vertical splitting (prefix + v) creates a new pane to the right of the current one.

Q: How can I synchronize input across multiple tmux panes simultaneously? A: Use prefix + s to toggle pane synchronization. When enabled, any input you type will be sent to all panes in the current window.

Q: Is there a way to resize tmux panes more efficiently than the default commands? A: Yes, the custom configuration includes a resize mode (prefix + r) that temporarily enables hjkl keys for intuitive pane resizing without needing the prefix key.

Q: How do I move panes around in tmux without destroying the layout? A: Use Ctrl+Arrow keys to swap panes directionally, or enter movement mode with prefix + k to navigate with hjkl keys.

Q: Can I make new tmux panes start in the same directory as the current pane? A: Yes, the configuration uses split-window -c "#{pane_current_path}" to ensure new panes inherit the current working directory.

Q: What are the benefits of changing tmux window indexing to start at 1 instead of 0? A: Starting at 1 makes window navigation more intuitive since most keyboards have number keys starting with 1, and it aligns better with human counting habits.

Q: How do I enable mouse support in tmux for easier pane selection and resizing? A: Add set -g mouse on to your configuration file, or toggle it during a session with prefix + m using the custom keybinding.

Q: What’s the purpose of the special movement and resize modes in this tmux configuration? A: These modes temporarily bind hjkl keys for navigation and resizing without requiring the prefix key, making pane management faster and more vim-like.

Q: How can I monitor multiple servers or processes efficiently using tmux? A: Create multiple panes for different servers, use pane synchronization for identical commands, and leverage the status bar to display relevant information like hostnames and timestamps.