Configuring tmux

Notes and config snippets, collected from around the internet

Tmux configuration involves customizing the behavior and appearance of the terminal multiplexer through a configuration file. By default, tmux looks for a user-specific configuration file at $XDG_CONFIG_HOME/tmux/tmux.conf or ~/.config/tmux/tmux.conf (as of tmux 3.2), and historically also ~/.tmux.conf. A global configuration file can be found at /etc/tmux.conf. Key aspects of tmux configuration include: Prefix Key: The default prefix key, Ctrl+b, can be changed to a more ergonomic key combination like Ctrl+a by unbinding the default and binding the new prefix in the configuration file.

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

Key Bindings: Custom key bindings can be defined for various actions, such as splitting panes, navigating between panes, and resizing them. For instance, hjkl can be bound for pane navigation in a Vim-like style. Mouse Support: Enabling mouse support allows for easier interaction with tmux, including resizing panes and scrolling through output using the mouse.

    set -g mouse on

Status Bar: The status bar’s appearance and content can be customized, including displaying information like the current time, system load, or active windows and panes. Plugins: The Tmux Plugin Manager (TPM) allows for easy installation and management of various plugins that extend tmux’s functionality, such as enhanced navigation or visual themes like Dracula TMUX. Session Options and Window Options: Various settings for sessions and windows can be configured, such as base index for windows, automatic window naming, and copy mode key bindings (e.g., using vi-style shortcuts). Reloading Configuration: A common practice is to bind a key to reload the configuration file, allowing for quick application of changes without restarting tmux.

bind r source-file ~/.tmux.conf \; display-message "tmux.conf reloaded" Example Configuration Snippets: Changing Prefix.

unbind C-b
set -g prefix C-a
bind C-a send-prefix Enabling Mouse Mode.

set -g mouse on Vim-like Pane Navigation. ```
bind h select-pane -L
bind j select-pane -D
bind k select-pane -U
bind l select-pane -R ```

Notes:

Using the keyboard Enter copy mode: Press the prefix key (Ctrl+b by default) followed by an opening bracket [. Scroll: Use the Up and Down arrow keys, Page Up, or Page Down keys to move through the buffer. Exit copy mode: Press q to return to normal operation. Using the mouse (requires configuration) If you’ve enabled mouse mode, you can scroll up and down with your mouse wheel just as you would in a regular terminal. To enable mouse mode, add the following line to your ~/.tmux.conf file and reload the configuration: set -g mouse on.

References