kevin tmux

tmux cheatsheet with example config

Sessions :new<CR> new session s list sessions $ name session Windows c create window w list windows n next window p previous window f find window , name window & kill window Panes % vertical split " horizontal split o…

Sessions

:new<CR>  new session
s  list sessions
$  name session

Windows

c  create window
w  list windows
n  next window
p  previous window
f  find window
,  name window
&  kill window

Panes

%  vertical split
"  horizontal split

o  swap panes
q  show pane numbers
x  kill pane
+  break pane into window (e.g. to select text by mouse to copy)
-  restore pane from window
⍽  space - toggle between layouts
<prefix> q (Show pane numbers)
<prefix> { (Move the current pane left)
<prefix> } (Move the current pane right)
<prefix> z toggle pane zoom

Custom configuration

# NOTES GENERAL
# tmux keybinds has priority 1 in the virtual terminal, tmux keybinds will collide with bash defaults and vim default keys, either change those or adapt tmux to work around these limitations
# always unbind before binding new keys 

# NOTES FLAGS/options
# -n = pressing keybind triggers action directly, instead of pressing bind and keybind, saves one keystroke
# -g =  If -g is given, the global session or window option is set.

# NOTES PREFIXES
# M-xxx = Meta/Alt + xxx 
# C-xxx = Control + xxx 

# NOTES SAMPLES/Templates
# bind -n l select-pane -R
# bind -n M-h select-pane -L

# Bind key
unbind C-b
set-option -g prefix `
# set-option -g prefix M-space

# Start windows and panes at 1, not 0
set -g base-index 1
setw -g pane-base-index 1

# Scroll back 
set -g history-limit 10000

# Make copy-mode vim styled
setw -g mode-keys vi

# Reload ~/.tmux.conf
bind C-r source-file ~/.tmux.conf \; display "Reloaded!"

# Window creation/Vim styled Pane splitting
bind-key h split-window -h
bind-key v split-window -v

# Window navigation/Vim styled Pane navigation
#INACTIVE
#bind-key h select-pane -L
#bind-key j select-pane -D
#bind-key k select-pane -U
#bind-key l select-pane -R

# Window navigation/Vim styled Pane navigation SINGLE PRESS
bind -n M-h select-pane -L
bind -n M-j select-pane -D
bind -n M-k select-pane -U
bind -n M-l select-pane -R

# COPY MODE VIM STYLED
# Copy mode, press v to highlight
bind -T copy-mode-vi v send -X begin-selection
# Copy mode, press y to yank
bind -T copy-mode-vi y send-keys -X copy-pipe-and-cancel "pbcopy"
# Copy mode, press p to paste
bind P paste-buffer

Default configuration, Documentation Highlight

man tmux 
/default 

The default command key bindings are:

           C-b         Send the prefix key (C-b) through to the application.
           C-o         Rotate the panes in the current window forwards.
           C-z         Suspend the tmux client.
           !           Break the current pane out of the window.
           "           Split the current pane into two, top and bottom.
           #           List all paste buffers.
           $           Rename the current session.
           %           Split the current pane into two, left and right.
           &           Kill the current window.
           '           Prompt for a window index to select.
           (           Switch the attached client to the previous session.
           )           Switch the attached client to the next session.
           ,           Rename the current window.
           -           Delete the most recently copied buffer of text.
           .           Prompt for an index to move the current window.
           0 to 9      Select windows 0 to 9.
           :           Enter the tmux command prompt.
           ;           Move to the previously active pane.
           =           Choose which buffer to paste interactively from a list.
           ?           List all key bindings.
           D           Choose a client to detach.
           L           Switch the attached client back to the last session.
           [           Enter copy mode to copy text or view the history.
           ]           Paste the most recently copied buffer of text.
           c           Create a new window.
           d           Detach the current client.
           f           Prompt to search for text in open windows.
           i           Display some information about the current window.
           l           Move to the previously selected window.
           m           Mark the current pane (see select-pane -m).
           M           Clear the marked pane.
           n           Change to the next window.
           o           Select the next pane in the current window.
           p           Change to the previous window.
           q           Briefly display pane indexes.
           r           Force redraw of the attached client.
           s           Select a new session for the attached client interactively.
           t           Show the time.
           w           Choose the current window interactively.
           x           Kill the current pane.
DEFAULT KEY BINDINGS
     tmux may be controlled from an attached client by using a key combination of a prefix key, ‘C-b’ (Ctrl-b) by default,
     followed by a command key.

     The default command key bindings are:

           C-b         Send the prefix key (C-b) through to the application.
           C-o         Rotate the panes in the current window forwards.
           C-z         Suspend the tmux client.
           !           Break the current pane out of the window.
           "           Split the current pane into two, top and bottom.
           #           List all paste buffers.
           $           Rename the current session.
           %           Split the current pane into two, left and right.
           &           Kill the current window.
           '           Prompt for a window index to select.
           (           Switch the attached client to the previous session.
           )           Switch the attached client to the next session.
           ,           Rename the current window.
           -           Delete the most recently copied buffer of text.
           .           Prompt for an index to move the current window.
           0 to 9      Select windows 0 to 9.
           :           Enter the tmux command prompt.
           ;           Move to the previously active pane.
           =           Choose which buffer to paste interactively from a list.
           ?           List all key bindings.
           D           Choose a client to detach.
           L           Switch the attached client back to the last session.
           [           Enter copy mode to copy text or view the history.
           ]           Paste the most recently copied buffer of text.
           c           Create a new window.
           d           Detach the current client.
           f           Prompt to search for text in open windows.
           i           Display some information about the current window.
           i           Display some information about the current window.
           l           Move to the previously selected window.
           m           Mark the current pane (see select-pane -m).
           M           Clear the marked pane.
           n           Change to the next window.
           o           Select the next pane in the current window.
           p           Change to the previous window.
           q           Briefly display pane indexes.
           r           Force redraw of the attached client.
           s           Select a new session for the attached client interactively.
           t           Show the time.
           w           Choose the current window interactively.
           x           Kill the current pane.
           z           Toggle zoom state of the current pane.
           {           Swap the current pane with the previous pane.
           }           Swap the current pane with the next pane.
           ~           Show previous messages from tmux, if any.
           Page Up     Enter copy mode and scroll one page up.
           Up, Down
           Left, Right
           Left, Right
                       Change to the pane above, below, to the left, or to the right of the current pane.
           M-1 to M-5  Arrange panes in one of the five preset layouts: even-horizontal, even-vertical, main-horizontal,
                       main-vertical, or tiled.
           Space       Arrange the current window in the next preset layout.
           M-n         Move to the next window with a bell or activity marker.
           M-o         Rotate the panes in the current window backwards.
           M-p         Move to the previous window with a bell or activity marker.
           C-Up, C-Down
           C-Left, C-Right
                       Resize the current pane in steps of one cell.
           M-Up, M-Down
           M-Left, M-Right
                       Resize the current pane in steps of five cells.

Example configuration, Documentation Highlight

/usr/share/doc/tmux/example_tmux.conf

#
# Example .tmux.conf
#
# By Nicholas Marriott. Public domain.
#

# Some tweaks to the status line
set -g status-right "%H:%M"
set -g window-status-current-style "underscore"

# If running inside tmux ($TMUX is set), then change the status line to red
%if #{TMUX}
set -g status-bg red
%endif

# Enable RGB colour if running in xterm(1)
set-option -sa terminal-overrides ",xterm*:Tc"

# Change the default $TERM to tmux-256color
set -g default-terminal "tmux-256color"

# No bells at all
set -g bell-action none

# Keep windows around after they exit
set -g remain-on-exit on

# Change the prefix key to C-a
set -g prefix C-a
unbind C-b
bind C-a send-prefix

# Turn the mouse on, but without copy mode dragging
set -g mouse on
unbind -n MouseDrag1Pane
unbind -Tcopy-mode MouseDrag1Pane

# Some extra key bindings to select higher numbered windows
bind F1 selectw -t:10
bind F2 selectw -t:11
bind F3 selectw -t:12
bind F4 selectw -t:13
bind F5 selectw -t:14
bind F6 selectw -t:15
bind F7 selectw -t:16
bind F8 selectw -t:17
bind F9 selectw -t:18
bind F10 selectw -t:19
bind F11 selectw -t:20
bind F12 selectw -t:21

# A key to toggle between smallest and largest sizes if a window is visible in
# multiple places
bind F set -w window-size

# Keys to toggle monitoring activity in a window and the synchronize-panes option
bind m set monitor-activity
bind y set synchronize-panes\; display 'synchronize-panes #{?synchronize-panes,on,off}'

# Create a single default session - because a session is created here, tmux
# should be started with "tmux attach" rather than "tmux new"
new -d -s0 -nirssi 'exec irssi'
set -t0:0 monitor-activity on
set  -t0:0 aggressive-resize on
neww -d -ntodo 'exec emacs ~/TODO'
setw -t0:1 aggressive-resize on
neww -d -nmutt 'exec mutt'
setw -t0:2 aggressive-resize on
neww -d
neww -d
neww -d

All custom keys, Source highlight

https://raw.githubusercontent.com/tmux/tmux/master/key-string.c

# q: Were is ctrl / alt keys?
# a: compare raw keycode 

	/* Function keys. */
	{ "F1",		KEYC_F1|KEYC_IMPLIED_META },
	{ "F2",		KEYC_F2|KEYC_IMPLIED_META },
	{ "F3",		KEYC_F3|KEYC_IMPLIED_META },
	{ "F4",		KEYC_F4|KEYC_IMPLIED_META },
	{ "F5",		KEYC_F5|KEYC_IMPLIED_META },
	{ "F6",		KEYC_F6|KEYC_IMPLIED_META },
	{ "F7",		KEYC_F7|KEYC_IMPLIED_META },
	{ "F8",		KEYC_F8|KEYC_IMPLIED_META },
	{ "F9",		KEYC_F9|KEYC_IMPLIED_META },
	{ "F10",	KEYC_F10|KEYC_IMPLIED_META },
	{ "F11",	KEYC_F11|KEYC_IMPLIED_META },
	{ "F12",	KEYC_F12|KEYC_IMPLIED_META },
	{ "IC",		KEYC_IC|KEYC_IMPLIED_META },
	{ "Insert",	KEYC_IC|KEYC_IMPLIED_META },
	{ "DC",		KEYC_DC|KEYC_IMPLIED_META },
	{ "Delete",	KEYC_DC|KEYC_IMPLIED_META },
	{ "Home",	KEYC_HOME|KEYC_IMPLIED_META },
	{ "End",	KEYC_END|KEYC_IMPLIED_META },
	{ "NPage",	KEYC_NPAGE|KEYC_IMPLIED_META },
	{ "PageDown",	KEYC_NPAGE|KEYC_IMPLIED_META },
	{ "PgDn",	KEYC_NPAGE|KEYC_IMPLIED_META },
	{ "PPage",	KEYC_PPAGE|KEYC_IMPLIED_META },
	{ "PageUp",	KEYC_PPAGE|KEYC_IMPLIED_META },
	{ "PgUp",	KEYC_PPAGE|KEYC_IMPLIED_META },
	{ "Tab",	'\011' },
	{ "BTab",	KEYC_BTAB },
	{ "Space",	' ' },
	{ "BSpace",	KEYC_BSPACE },
	{ "Enter",	'\r' },
	{ "Escape",	'\033' },

	/* Arrow keys. */
	{ "Up",		KEYC_UP|KEYC_CURSOR|KEYC_IMPLIED_META },
	{ "Down",	KEYC_DOWN|KEYC_CURSOR|KEYC_IMPLIED_META },
	{ "Left",	KEYC_LEFT|KEYC_CURSOR|KEYC_IMPLIED_META },
	{ "Right",	KEYC_RIGHT|KEYC_CURSOR|KEYC_IMPLIED_META },

	/* Numeric keypad. */
	{ "KP/",	KEYC_KP_SLASH|KEYC_KEYPAD },
	{ "KP*",	KEYC_KP_STAR|KEYC_KEYPAD },
	{ "KP-",	KEYC_KP_MINUS|KEYC_KEYPAD },
	{ "KP7",	KEYC_KP_SEVEN|KEYC_KEYPAD },
	{ "KP8",	KEYC_KP_EIGHT|KEYC_KEYPAD },
	{ "KP9",	KEYC_KP_NINE|KEYC_KEYPAD },
	{ "KP+",	KEYC_KP_PLUS|KEYC_KEYPAD },
	{ "KP4",	KEYC_KP_FOUR|KEYC_KEYPAD },
	{ "KP5",	KEYC_KP_FIVE|KEYC_KEYPAD },
	{ "KP6",	KEYC_KP_SIX|KEYC_KEYPAD },
	{ "KP1",	KEYC_KP_ONE|KEYC_KEYPAD },
	{ "KP2",	KEYC_KP_TWO|KEYC_KEYPAD },
	{ "KP3",	KEYC_KP_THREE|KEYC_KEYPAD },
	{ "KPEnter",	KEYC_KP_ENTER|KEYC_KEYPAD },
	{ "KP0",	KEYC_KP_ZERO|KEYC_KEYPAD },
	{ "KP.",	KEYC_KP_PERIOD|KEYC_KEYPAD },

	/* Mouse keys. */
	KEYC_MOUSE_STRING(MOUSEDOWN1, MouseDown1),
	KEYC_MOUSE_STRING(MOUSEDOWN2, MouseDown2),
	KEYC_MOUSE_STRING(MOUSEDOWN3, MouseDown3),
	KEYC_MOUSE_STRING(MOUSEDOWN6, MouseDown6),
	KEYC_MOUSE_STRING(MOUSEDOWN7, MouseDown7),
	KEYC_MOUSE_STRING(MOUSEDOWN8, MouseDown8),
	KEYC_MOUSE_STRING(MOUSEDOWN9, MouseDown9),
	KEYC_MOUSE_STRING(MOUSEDOWN10, MouseDown10),
	KEYC_MOUSE_STRING(MOUSEDOWN11, MouseDown11),
	KEYC_MOUSE_STRING(MOUSEUP1, MouseUp1),
	KEYC_MOUSE_STRING(MOUSEUP2, MouseUp2),
	KEYC_MOUSE_STRING(MOUSEUP3, MouseUp3),
	KEYC_MOUSE_STRING(MOUSEUP6, MouseUp6),
	KEYC_MOUSE_STRING(MOUSEUP7, MouseUp7),
	KEYC_MOUSE_STRING(MOUSEUP8, MouseUp8),
	KEYC_MOUSE_STRING(MOUSEUP9, MouseUp9),
	KEYC_MOUSE_STRING(MOUSEUP10, MouseUp10),
	KEYC_MOUSE_STRING(MOUSEUP11, MouseUp11),
	KEYC_MOUSE_STRING(MOUSEDRAG1, MouseDrag1),
	KEYC_MOUSE_STRING(MOUSEDRAG2, MouseDrag2),
	KEYC_MOUSE_STRING(MOUSEDRAG3, MouseDrag3),
	KEYC_MOUSE_STRING(MOUSEDRAG6, MouseDrag6),
	KEYC_MOUSE_STRING(MOUSEDRAG7, MouseDrag7),
	KEYC_MOUSE_STRING(MOUSEDRAG8, MouseDrag8),
	KEYC_MOUSE_STRING(MOUSEDRAG9, MouseDrag9),
	KEYC_MOUSE_STRING(MOUSEDRAG10, MouseDrag10),
	KEYC_MOUSE_STRING(MOUSEDRAG11, MouseDrag11),
	KEYC_MOUSE_STRING(MOUSEDRAGEND1, MouseDragEnd1),
	KEYC_MOUSE_STRING(MOUSEDRAGEND2, MouseDragEnd2),
	KEYC_MOUSE_STRING(MOUSEDRAGEND3, MouseDragEnd3),
	KEYC_MOUSE_STRING(MOUSEDRAGEND6, MouseDragEnd6),
	KEYC_MOUSE_STRING(MOUSEDRAGEND7, MouseDragEnd7),
	KEYC_MOUSE_STRING(MOUSEDRAGEND8, MouseDragEnd8),
	KEYC_MOUSE_STRING(MOUSEDRAGEND9, MouseDragEnd9),
	KEYC_MOUSE_STRING(MOUSEDRAGEND10, MouseDragEnd10),
	KEYC_MOUSE_STRING(MOUSEDRAGEND11, MouseDragEnd11),
	KEYC_MOUSE_STRING(WHEELUP, WheelUp),
	KEYC_MOUSE_STRING(WHEELDOWN, WheelDown),
	KEYC_MOUSE_STRING(SECONDCLICK1, SecondClick1),
	KEYC_MOUSE_STRING(SECONDCLICK2, SecondClick2),
	KEYC_MOUSE_STRING(SECONDCLICK3, SecondClick3),
	KEYC_MOUSE_STRING(SECONDCLICK6, SecondClick6),
	KEYC_MOUSE_STRING(SECONDCLICK7, SecondClick7),
	KEYC_MOUSE_STRING(SECONDCLICK8, SecondClick8),
	KEYC_MOUSE_STRING(SECONDCLICK9, SecondClick9),
	KEYC_MOUSE_STRING(SECONDCLICK10, SecondClick10),
	KEYC_MOUSE_STRING(SECONDCLICK11, SecondClick11),
	KEYC_MOUSE_STRING(DOUBLECLICK1, DoubleClick1),
	KEYC_MOUSE_STRING(DOUBLECLICK2, DoubleClick2),
	KEYC_MOUSE_STRING(DOUBLECLICK3, DoubleClick3),
	KEYC_MOUSE_STRING(DOUBLECLICK6, DoubleClick6),
	KEYC_MOUSE_STRING(DOUBLECLICK7, DoubleClick7),
	KEYC_MOUSE_STRING(DOUBLECLICK8, DoubleClick8),
	KEYC_MOUSE_STRING(DOUBLECLICK9, DoubleClick9),
	KEYC_MOUSE_STRING(DOUBLECLICK10, DoubleClick10),
	KEYC_MOUSE_STRING(DOUBLECLICK11, DoubleClick11),
	KEYC_MOUSE_STRING(TRIPLECLICK1, TripleClick1),
	KEYC_MOUSE_STRING(TRIPLECLICK2, TripleClick2),
	KEYC_MOUSE_STRING(TRIPLECLICK3, TripleClick3),
	KEYC_MOUSE_STRING(TRIPLECLICK6, TripleClick6),
	KEYC_MOUSE_STRING(TRIPLECLICK7, TripleClick7),
	KEYC_MOUSE_STRING(TRIPLECLICK8, TripleClick8),
	KEYC_MOUSE_STRING(TRIPLECLICK9, TripleClick9),
	KEYC_MOUSE_STRING(TRIPLECLICK10, TripleClick10),
	KEYC_MOUSE_STRING(TRIPLECLICK11, TripleClick11)

Cool configs from around the web


# https://stackoverflow.com/a/7775786
# supposedly GNU Screen like tmux configuration (fivemin NOT tested)

# Prefix key
set -g prefix C-a
unbind C-b
bind C-a send-prefix

# Keys
bind k confirm kill-window
bind K confirm kill-server
bind % split-window -h
bind : split-window -v
bind < resize-pane -L 1
bind > resize-pane -R 1
bind - resize-pane -D 1
bind + resize-pane -U 1
bind . command-prompt
bind a last-window
bind space command-prompt -p index "select-window"
bind r source-file ~/.tmux.conf

# Options
set -g bell-action none
set -g set-titles on
set -g set-titles-string "tmux (#I:#W)"
set -g base-index 1
set -g status-left ""
set -g status-left-attr bold
set -g status-right "tmux"
set -g pane-active-border-bg black
set -g pane-active-border-fg black
set -g default-terminal "screen-256color"

# Window options
setw -g monitor-activity off
setw -g automatic-rename off

# Colors
setw -g window-status-current-fg colour191
set -g status-bg default
set -g status-fg white
set -g message-bg default
set -g message-fg colour191