Tmux : TerminalMultiplexer

Tmux Conf

TMUX=1 gnome-terminal tmux capture-pane -pS -1000000 -t 0 > file.out

Pane to new Windows == break pane o

join-pane -s
join-pane -t
break-pane   (!)

Vertical to horizontal

C-b space (bound to next-layout by default) cycles through available layouts, you can also use the select-layout command.

M-1 to M-5 Arrange panes in one of the five preset layouts: even- horizontal, even-vertical, main-horizontal, main- vertical, or tiled.

On OS X, M is Esc, i.e. Ctrl-b Esc-1.

Clipboard

tmux save-buffer - | xclip -i

Get help

tmux list-keys
tmux list-commands
tmux info
tmux source-file ~/.tmux.conf
    list-keys -T copy-mode-vi
C-b ?

Display a list of keyboard shortcuts:

    tmux list-sessions
    C-b w

List windows

    C-b s

List sessions

Tips

tmux cheat sheet

(C-x means ctrl+x, M-x means alt+x)

Prefix key

The default prefix is C-b. If you (or your muscle memory) prefer C-a, you need to add this to ~/.tmux.conf:

remap prefix to Control + a

set -g prefix C-a

bind ‘C-a C-a’ to type ‘C-a’

bind C-a send-prefix
unbind C-b

I’m going to assume that C-a is your prefix.

Navigate using Vim or Emacs shortcuts, depending on the value of mode-keys. Emacs is the default, and if you want Vim shortcuts for help and copy modes (e.g. j, k, C-u, C-d), add the following line to ~/.tmux.conf:

setw -g mode-keys vi

Any command mentioned in this list can be executed as tmux something or C-a :something (or added to ~/.tmux.conf).

Copy mode

    bind-key -T copy-mode-vi 'v' send -X begin-selection
    bind-key -T copy-mode-vi 'y' send -X copy-selection-and-cancel
    <C-b> =

show the yank ring

Sessions, windows, panes

Session is a set of windows, plus a notion of which window is current.

Window is a single screen covered with panes. (Once might compare it to a ‘virtual desktop’ or a ‘space’.)

Pane is a rectangular part of a window that runs a specific command, e.g. a shell.

swap-window -s 3 -t 1 swap-window -t 0 move-window -t 0 bind-key T swap-window -t 0 bind-key -n C-S-Left swap-window -t -1 bind-key -n C-S-Right swap-window -t +1

Sessions

Windows

Managing split panes

Split: Creating a new pane by splitting an existing one:

C-a "          split vertically (top/bottom)
C-a %          split horizontally (left/right)

Switch: between panes:

C-a left       go to the next pane on the left
C-a right      (or one of these other directions)
C-a up
C-a down
C-a o          go to the next pane (cycle through all of them)
C-a ;          go to the ‘last’ (previously used) pane
C-a q 0 ... 9  go to pane number 0 ... 9

Move: panes around:

C-a {          move the current pane to the previous position
C-a }          move the current pane to the next position
C-a C-o        rotate window ‘up’ (i.e. move all panes)
C-a M-o        rotate window ‘down’
C-a !          move the current pane into a new separate
               window (‘break pane’)
C-a :move-pane -t :3.2
               split window 3's pane 2 and move the current pane there

Resize: panes:

C-a M-up, C-a M-down, C-a M-left, C-a M-right
               resize by 5 rows/columns
C-a C-up, C-a C-down, C-a C-left, C-a C-right
               resize by 1 row/column
C-a z          toggle pane zoom

Evenify: Applying predefined layouts:

C-a M-1        switch to even-horizontal layout
C-a M-2        switch to even-vertical layout
C-a M-3        switch to main-horizontal layout
C-a M-4        switch to main-vertical layout
C-a M-5        switch to tiled layout
C-a space      switch to the next layout

Other:

C-a x          kill the current pane
C-a q          display pane numbers for a short while

Copy mode

:setw -g mode-keys vi # use vi keys in buffer

Function                vi             emacs
Back to indentation     ^              M-m
Clear selection         Escape         C-g
Copy selection          Enter          M-w
Cursor down             j              Down
Cursor left             h              Left
Cursor right            l              Right
Cursor to bottom line   L
Cursor to middle line   M              M-r
Cursor to top line      H              M-R
Cursor up               k              Up
Delete entire line      d              C-u
Delete to end of line   D              C-k
End of line             $              C-e
Goto line               :              g
Half page down          C-d            M-Down
Half page up            C-u            M-Up
Next page               C-f            Page down
Next word               w              M-f
Paste buffer            p              C-y
Previous page           C-b            Page up
Previous word           b              M-b
Quit mode               q              Escape
Scroll down             C-Down or J    C-Down
Scroll up               C-Up or K      C-Up
Search again            n              n
Search backward         ?              C-r
Search forward          /              C-s
Start of line           0              C-a
Start selection         Space          C-Space
Transpose chars                        C-t

From and to copy mode:

Ctrl + b ]

Paste contents of buffer_0

Ctrl + b [

Enter copy mode

Ctrl + b PgUp

Enter copy mode and scroll one page up

q

Quit mode

Spacebar

Start selection

Esc

Clear selection

Enter

Copy selection

Copy commands

:show-buffer

display buffer_0 contents

:capture-pane

copy entire visible contents of pane to a buffer

:list-buffers

Show all buffers

:choose-buffer

Show all buffers and paste selected

:save-buffer buf.txt

Save buffer contents to buf.txt

:delete-buffer -b 1

delete buffer_1

Other config file settings

Force a reload of the config file on C-a r: unbind r bind r source-file ~/.tmux.conf

Some other settings that I use: setw -g xterm-keys on

.tmux.conf

set-option -g allow-rename off
set -g status-bg cyan
set-option -g prefix C-a
unbind C-b 

key bindings (other cheat)

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.

Key bindings may be changed with the bind-key and unbind-key commands.