Tmux Basics

My config

set -g mouse on

# reload
bind r source-file ~/.tmux.conf

# vi copy mode
bind v copy-mode
bind -T copy-mode-vi v send -X begin-selection
bind -T copy-mode-vi y send-keys -X copy-selection-and-cancel
unbind P
bind p paste-buffer

# remap prefix to alt ;
unbind C-b
set-option -g prefix M-\;
bind M-\; send-prefix

# split panes using | and -
bind H split-window -h
bind V split-window -v
unbind '"'
unbind %

# switch panes using alt-hjkl
bind -n M-h select-pane -L
bind -n M-l select-pane -R
bind -n M-k select-pane -U
bind -n M-j select-pane -D

# Design
set -g status-interval 2
set -g status-justify centre
set -g status-left ' #h '
set -g status-right ' %Y-%m-%d %H:%M '

Cheat Sheet

Combo Action
M-; prefix (command mode)
prefix-r reload config (~/.tmux.conf)
prefix-H horizontal split
prefix-V vertical split
prefix-v enter copy-mode (visual). Use v to select in copy-mode and y to yank, exiting copy mode
prefix-p paste from the buffer
M-h move left pane
M-l move right pane
M-k move up pane
M-j move down pane
prefix-w #Choosing sessions, windows and panes
starts with sessions expanded so windows are shown and with the current window in the attached session selected
prefix-s #Choosing sessions, windows and panes
starts showing only sessions and with the attached session selected

Choosing sessions, windows and panes

Items in the tree are tagged by pressing t and untagged by pressing t again. Tagged items are shown in bold and with * after their name. All tagged items may be untagged by pressing T. Tagged items may be killed together by pressing X, or a command applied to them all by pressing : for a prompt.

Each item in the tree has as shortcut key in brackets at the start of the line. Pressing this key will immediately choose that item (as if it had been selected and Enter pressed). The first ten items are keys 0 to 9 and after that keys M-a to M-z are used.

This is a list of the keys available in tree mode without pressing the prefix key:

Formats - used in status bar etc

https://man.openbsd.org/tmux.1#FORMATS

Key Function
Enter Change the attached session, current window or active pane
Up Select previous item
Down Select next item
Right Expand item
Left Collapse item
x Kill selected item
X Kill tagged items
< Scroll preview left
> Scroll preview right
C-s Search by name
n Repeat last search
t Toggle if item is tagged
T Tag no items
C-t Tag all items
: Prompt for a command to run for the selected item or each tagged item
O Change sort field
r Reverse sort order
v Toggle preview
q Exit tree mode

Defaults

key combo action
Ctrl bc Create new window
Ctrl bd Detach from session
Command Action
tmux new -t weechat create a new session called weechat
tmux attach -t weechat attach (resume) a session called weechat

Splitting

split-window [-bdfhIvPZ] [-c start-directory] [-e environment] [-l size] [-t target-pane] [shell-command] [-F format]

(alias: splitw)

Create a new pane by splitting target-pane: -h does a horizontal split and -v a vertical split; if neither is specified, -v is assumed. […] The -b option causes the new pane to be created to the left of or above target-pane. The -f option creates a new pane spanning the full window height (with -h) or full window width (with -v), instead of splitting the active pane. […]

Aliases

ctrl-b + % Vertical
ctrl-b + " Horizontal

You can also make multiple splits then use ctrl-b + A[1-5] to use pre-made layouts

Scrolling

ctrl-b + [ then arrows

or

ctrl-b + :set-window-option mode-keys vi

and

shift-j and shift-k for pages or just j and k for lines

Key mappings

https://unix.stackexchange.com/questions/140007/what-are-valid-keys-for-tmux

Available Keys

Look at man tmux, search / for KEY BINDINGS:

tmux allows a command to be bound to most keys, with or without a prefix key.

When specifying keys, most represent themselves (for example ‘A’ to ‘Z’). Ctrl keys may be prefixed with ‘C-’ or ‘^’, and Alt (meta) with ‘M-’.

In addition, the following special key names are accepted:

Up, Down, Left, Right, BSpace, BTab, DC (Delete), End, Enter, Escape, F1 to F20, Home, IC (Insert), NPage/PageDown/PgDn, PPage/PageUp/PgUp, Space, and Tab. Note that to bind the ‘"’ or ‘'’ keys, quotation marks are necessary [...]

M-S-Left should be Alt+Shift+Left for example.

List all bound keys

To list all key bindings, simply press Ctrl-b then ? while in a tmux session.

This is also documented in man tmux in section EXAMPLES:

Typing ‘C-b ?’ lists the current key bindings in the current window; up and down may be used to navigate the list or ‘q’ to exit from it.

You can also list all key-bindings via tmux list-keys. If you want to check for already set keys, you can grep it's output to check, if it's already set.

Research

To find more via Google, search for Section names in man tmux - just type in tmux default key bindings for example :). But often man tmux is sufficient.

This site is a very good documentation about tmux and pops up, if you search for said string in Google.

Arch wiki is always good, too.