Tmux Shortcuts and Configuration
Use the default tmux prefix, Ctrl+b, before most of the shortcuts below.
Essential Tmux Shortcuts
Session management
tmux new -s [session-name]: Creates a new tmux session with a custom name.tmux ls: Lists all active tmux sessions.tmux attach -t [session-name]: Attaches to an existing session.tmux kill-session -t [session-name]: Terminates a specific session. Use this carefully because it closes the whole session.
Window management
Prefix c: Creates a new window within the current session.Prefix ,: Renames the current window.Prefix n: Moves to the next window in the session.Prefix p: Moves to the previous window in the session.Prefix [0-9]: Switches directly to the window with the specified number.
Pane management
Prefix %: Splits the current pane into left and right panes, with the new pane on the right.Prefix ": Splits the current pane into panes above and below, with the new pane below it.Prefix arrow key: Moves between panes in the direction of the arrow key.Prefix z: Toggles zoom on the current pane.
Copy mode
Prefix [: Enters copy mode so you can inspect terminal history and select text.- The Space and Enter bindings below depend on whether copy mode uses vi or emacs keys.
Space(in vi-style copy mode): Starts text selection.Enter(in vi-style copy mode): Copies the selected text to the tmux paste buffer.Prefix ]: Pastes text from the tmux paste buffer.
Miscellaneous
Prefix d: Detaches from the current session while leaving it running.Prefix ?: Displays all tmux shortcuts.Prefix :: Enters command mode for typing tmux commands directly.Prefix t: Shows a clock in the current pane.
Customizing Your Tmux Configuration
A .tmux.conf file can change the prefix, pane shortcuts, and mouse behavior. This example:
Enable mouse control
set -g mouse on
Remap prefix from ‘C-b’ to ‘C-a’
unbind C-b set-option -g prefix C-a bind-key C-a send-prefix
Split panes using | and -
bind | split-window -h bind - split-window -v unbind ’”’ unbind %
Switch panes using Alt-arrow without prefix
bind -n M-Left select-pane -L bind -n M-Right select-pane -R bind -n M-Up select-pane -U bind -n M-Down select-pane -D
Prevent programs from changing window names via terminal escape sequences
set-option -g allow-rename off
It enables mouse support, changes the prefix from Ctrl+b to Ctrl+a, remaps pane splitting to | and -, adds Alt+Arrow pane switching, and prevents programs from changing the window name through terminal escape sequences. It does not prevent every kind of automatic renaming.
Styling Your Tmux
This example changes pane borders and the status bar:
Pane borders
set -g pane-border-style ‘fg=red’ set -g pane-active-border-style ‘fg=yellow’
Status bar
set -g status-position bottom set -g status-style ‘fg=red’ set -g status-right ‘%Y-%m-%d %H:%M ’ setw -g window-status-current-style ‘fg=black bg=red’ setw -g window-status-style ‘fg=red bg=black’
The status bar stays at the bottom, shows the date and time, and uses red and yellow for the borders and active window.