Organized Development With Tmux

by Doug Bell
(he, him, his)
@preaction
preaction
preaction.me/tmux
CC-BY-SA 4.0

For navigation help, press ?
For speaker view and notes, press S
For full-screen, press F

Tmux

screen

Installing

Starting Tmux

Terminal window with the command 'tmux' typed-in
Terminal window running 'tmux'
Tmux window with session name highlighted
Tmux window with window information highlighted

0:zsh*

Tmux window with bottom right corner highlighted
Tmux window with 'ps u' typed in a shell prompt
Tmux window with output from 'ps u'
Tmux window with 'exit' typed in a shell prompt
Terminal window after exiting Tmux

Detach

Attach

Terminal window with the command 'tmux' typed-in
Terminal window running 'tmux'

Ctrl+b d

Terminal showing as detached from tmux session 0
Terminal showing "tmux attach-session" typed in a prompt
Terminal window running 'tmux'

SSH

Detached Tasks

Windows

Terminal window running 'tmux'
Terminal window running 'tmux'
Terminal window showing the vim startup screen

Ctrl+b c

Tmux window showing a command prompt and two windows in the status bar
Tmux window with the new window in the status bar highlighted

1:zsh*

Tmux window with the previous window in the status bar highlighted

0:vim-

Tmux window showing a command prompt and two windows in the status bar

Ctrl+b l Ctrl+b p Ctrl+b 0

Terminal window showing the vim startup screen

Ctrl+b l Ctrl+b n Ctrl+b 1

Tmux window showing a command prompt and two windows in the status bar
Tmux window showing the manual page for Tmux
Tmux window showing the word "exit" typed into the command prompt
Tmux window showing our first window with Vim after the second window is destroyed
Tmux window highlighting the area of the status bar where the destroyed window was

Scroll Buffer

Tmux window showing a "ps au" command typed in
Tmux window showing the bottom of the output of "ps
au"
Terminal window with a Tmux status bar in the middle instead of on the
bottom
Tmux window showing the bottom of the output of "ps
au"

Copy Mode Ctrl+b [

Tmux window in copy mode
Tmux window highlighting the window name in the status bar enclosed in
square brackets

1:[tmux]*

Tmux window highlighting the scroll position indicator in the upper
right

[0/198]

Tmux window in copy mode

⬅️ ⬇️ ⬆️ ➡️ PgUp PgDn

Tmux window in copy mode

h j k l Ctrl+f Ctrl+b g G

Tmux window scrolled to the top
Tmux window in copy mode

? /

Tmux window showing (search up) in the status
bar
Tmux window showing (search up) in the status bar,
highlighted

(search up) tmux

Tmux window showing search results highlighted
Tmux window highlighting the highlighted search
results
Tmux window highlighting the highlighted search
results
Tmux window highlighting the search status bar at the
top
Tmux window showing search results highlighted

n N

Tmux window showing cursor on the next
result
Tmux window showing cursor on the next
result, highlighted
Tmux window showing cursor on the next
result

q

Tmux window showing the bottom of the output of "ps
au"
Tmux window scrolled to the top

Space

Tmux window showing selected text

Ctrl+w Enter

Tmux window showing vim

Ctrl+b ]

Tmux window showing vim with pasted text
inside

Window Panes

Tmux window showing vim

Ctrl+b %

Tmux window split vertically showing vim on the left, a shell on the
right

Ctrl+b "

Tmux window split vertically with the right pane split
horizontally
Tmux window split vertically, with the right pane split horizontally,
and then the right-bottom pane split vertically
Tmux window split vertically, with the right pane split horizontally,
the right-bottom pane split vertically, and then the right-bottom-right
pane split horizontally
Tmux window split vertically, with the right pane split horizontally,
and then the right-bottom pane split vertically
Tmux window split vertically with the right pane split
horizontally
Tmux window split vertically showing vim on the left, a shell on the
right

Ctrl+b ⬅️ ⬅️ ⬇️ ⬆️ ➡️

Tmux window split vertically showing vim on the left, a shell on the
right, with the cursor in the vim window

Ctrl+b z

Tmux window with editor pane zoomed
Tmux window with editor pane zoomed showing window in status bar
highlighted

0:vim*Z

The Basics of Tmux

Start / Stop

Attach / Detach

Windows

Scroll buffer

Panes

Configuration

Examples

Config File

~/.tmux.conf

Vim window showing ":e" command to edit
~/.tmux.conf

Setting the Prefix

Tmux

Ctrl+b

Screen

Ctrl+a

Custom

Ctrl+s

vim window editing ~/.tmux.conf, a new
file

set -g prefix C-s

vim window showing set prefix in config file

unbind C-b

vim window showing unbind command added to config
file

bind C-s send-prefix

vim window showing bind for send-prefix added to
config

Window Index

1 2 3 ... 0

0 1 2 ... 9

1 2 3 ... 0

0 1 2 ... 9

vim window showing bind for send-prefix added to
config

set -g base-index 1

vim window showing set base-index

Escape Time

Escape Sequence

Esc [D
Esc [C
Esc [1m

🏃 ^[D

🚶 ^   [   D

🕺 ^      [      D

Vim + Tmux

vim window showing set base-index

set -g escape-time 20

vim window showing set escape-time
⬅️⬇️⬆️➡️
HJKL
vim window showing set escape-time

bind h select-pane -L bind j select-pane -D bind k select-pane -U bind l select-pane -R

vim window showing binds for
select-pane
vim window showing binds for
select-pane

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

Reloading Config

vim window showing saved config file

Ctrl+b :

tmux window showing the command prompt
tmux window highlighting the command
bar
tmux window showing the command prompt

:source ~/.tmux.conf

vim window showing saved config file

Theming

vim window showing the config file
vim window highlighting the tmux status bar
vim window highlighting the right status area
vim window showing the config file

set -g status-bg black set -g status-fg white

vim window showing config file with status-bg and
status-fg

set -g status-left-length 20 set -g status-right-length 20

vim window showing config file with status left/right
length

Ctrl+b :

:source ~/.tmux.conf

vim window showing new colors and layout
vim window highlighting the bottom right status
area
vim window showing new colors and layout

Mouse 🐭 Tmux

set -g mouse on

Organizing Sessions and Windows

Terminal window with <code>tmux</code> command typed-in
Tmux window with session 1 in the bottom left
Tmux window with session 1 highlighted
Tmux window with session 1 in the bottom left
Terminal window showing detached from session
1
Terminal window showing "tmux attach" typed-in
Tmux window showing session 1
Tmux window showing session 1
Tmux window showing error for trying to attach inside
tmux
Terminal window showing <code>tmux attach -t 0</code> typed
in
Tmux window showing session 0
Terminal window showing <code>tmux ls</code> typed-in
Terminal window showing output from <code>tmux ls</code>

Naming Sessions

Tmux window showing session 1

Ctrl+b :

Ctrl+b $

Tmux window showing command line open

:rename-session talk

Tmux window showing 'rename-session' command
typed-in
Tmux window showing new session name
Tmux window highlighting session
name
Terminal window showing <code>tmux ls</code> output with new session
name
Terminal window showing <code>tmux ls</code> output with new session name
highlighted
Terminal window showing <code>tmux ls</code> output with attached
highlighted
Terminal window showing <code>tmux new</code> typed in

tmux new-session

Terminal window showing <code>tmux new</code> typed in

tmux new -s bugfix

Tmux window showing 'bugfix' session
name

Session Organization

Terminal window showing tmux ls with multiple
sessions

Naming Windows

Tmux window showing vim and zsh windows
Tmux window highlighting the vim window
Tmux window highlighting the zsh window
Tmux window showing vim and zsh windows
Tmux window showing vim and 2 zsh windows
Tmux window showing vim and 2 zsh windows
Tmux window showing vim and 2 zsh windows

Ctrl+b ,

:rename-window

Tmux window showing (rename-window) command prompt

(rename-window) zsh edit

Tmux window showing windows named "edit", "test", and
"docs"
Tmux window highlighting the "edit" window
Tmux window highlighting the "test" window
Tmux window highlighting the "docs" window

Automation

Tmux Session

Blog Session

tmux session named "blog" with one window, editor on the left, shell
on the right

Backend Session

tmux session named "backend" with one window named "edit", and another
named "test"

CMS Session

tmux session named "yancy" with three windows, "edit", "test", and
"db"

Tedious Setup

Don't Forget!

Automatic Session

Tmux Commands

Run

Tmux Commands

Anywhere

Empty shell window

tmux new -s yancy -d

Shell window with "tmux new" command executed"
Shell window with "tmux ls" command executed"

Shell Script

if ! tmux has-session -t yancy; then
tmux new -s yancy -d
  tmux new-window -t yancy:2
  tmux split-window -t yancy:2 -v
  tmux send-keys -t yancy:1 vim Enter
  tmux send-keys -t yancy:2.0 \
    morbo bin/yancy Enter

  tmux send-keys -t yancy:2.1 \
    export TEST_YANCY_EXAMPLES=1 Enter

  tmux new-window -t yancy:3 \
    postgres -D perl/Yancy/db/pg

  tmux split-window -t yancy:3 \
    mysqld --datadir=$HOME/db/mysql

fi
tmux attach -t yancy

Other Solutions

Tmuxifier

Teamocil

Wrap-Up

Questions?