TMUX Reference

A quick reference for all the TMUX shortcuts.

Sessions

Create and delete

Create new session

  • tmux
  • tmux new
  • tmux new-session
  • new

Create new session with name

  • tmux new-session -s NAME
  • new -s NAME

Create new session with session and window name

  • tmux new -s S_NAME -n W_NAME

Create or attach to session with name

  • tmux new-session -A -s NAME

Kill session

  • kill-session

Kill session by name

  • tmux kill-session -t NAME
  • tmux kill-ses -t NAME
  • kill-session -t NAME

Kill other sessions

  • tmux kill-session -a

Kill all sessions except

  • tmux kill-session -a -t NAME

List sessions

  • tmux ls
  • tmux list-sessions
  • ctrl + b,s

List sessions w/ windows

  • ctrl + b,w

Goto previous session

  • ctrl + b,(
Goto next session

For this to be helpful, you need to know what the next session is. That can be hard to find if you rename sessions because ctrl + b + s ‘s default order is by name.


To change the default order to be by index, you can use add this snippet to your ~/tmux.conf

bind s choose-tree -sZ -O index

From within the choose-tree menu, you can temporarily toggle through order with ctrl + b + shift + o.

  • ctrl + b,)

Goto last active session

  • ctrl + b,L

Attach to last session

  • tmux a
  • tmux at
  • tmux attach
  • tmux attach-session

Attach to session by NAME

  • tmux a -t NAME
  • tmux at -t NAME
  • tmux attach -t NAME
  • tmux attach-session -t NAME

Detach from session

  • ctrl + b,d

Detach others on the session (todo)

  • attach -d

Show list of sessions to detatch from

  • ctrl + b,D

Organization

Rename session

  • ctrl + b,$
  • rename-session NAME

Windows

Create and delete

Create window

  • ctrl + b,c

Kill window

  • ctrl + b,&

Search for window

  • ctrl + b,f

List windows

  • ctrl + b,w

Goto previous window

  • ctrl + b,p

Goto next window

  • ctrl + b,n
Goto prev/next window (VIM)

This requires updating your tmux.conf

bind -n M-H previous-window
bind -n M-L next-window
  • ctrl + shift + h
  • ctrl + shift + l

Goto last active window

  • ctrl + b,l

Switch window by number

  • ctrl + b,0 … 9

Organization

Rename current window

  • ctrl + b,,
Swap window order (absolute)
  • -s = source
  • -t = target
  • swap-window -s 2 -t

Swap window order (relative)

  • swap-window -t -1

Move window between sessions (by name)

  • movew -s foo:0 -t bar:9

Move window between sessions (by number)

  • movew -s 0:0 -t 1:9

Reposition window in the current Session (todo)

  • move-window -s S_NAME:W_NAME
  • movew -s 0:9

Renumber windows to remove gap in the sequence (todo)

  • move-window -r
  • movew -r

Misc

Display information about the current window

  • ctrl + b,i

Panes

Create and kill

Create horizontal split

  • ctrl + b,%
  • split-window -h

Create vertical split

  • ctrl + b,
  • split-window -v

Kill pane

  • ctrl + b,x

Goto pane in direction

  • ctrl + b,
  • ctrl + b,
  • ctrl + b,
  • ctrl + b,
Goto pane in direction (VIM)

This requires updating your tmux.conf

bind h select-pane -L
bind j select-pane -D
bind k select-pane -U
bind l select-pane -R
  • ctrl + h
  • ctrl + j
  • ctrl + k
  • ctrl + l
Goto next pane

Fun fact: there is no builtin shortcut for going to prev pane.

  • ctrl + b,o

Goto last active pane

  • ctrl + b,;

Show pane numbers

  • ctrl + b,q

Switch/select pane by number

  • ctrl + b,0…9

Toggle pane zoom

  • ctrl + b,z

Organization

Resize current pane

Note: on MacOS you have to disable Mission Control keyboard shortcuts for these to work. (link)

  • ctrl + b + ↑
  • ctrl + b + →
  • ctrl + b + ↓
  • ctrl + b + ←
  • ctrl + b,ctrl + ↑
  • ctrl + b,ctrl + →
  • ctrl + b,ctrl + ↓
  • ctrl + b,ctrl + ←

Spread panes out evenly

  • ctrl + b,E

Swap current pane with prev

  • ctrl + b,{

Swap current pane with next

  • ctrl + b,}

Rotate panes clockwise

  • ctrl + b,ctrl + o

Rotate panes counter clockwise

  • ctrl + b,option + o

Rearrange panes in 1 of 7 layout presets

  • ctrl + b,option + 0…7

Cycle through layout presets

  • ctrl + b,space

Window

Join two windows as panes (Merge window 2 to window 1 as panes) ????

  • join-pane -s 2 -t 1

Move pane from one window to another


The example moves pane 1 in window 2 to window 1 right after the 3rd pane.

  • join-pane -s 2.1 -t 1.3

Toggle synchronize-panes


Setting this option on will send the same command to each pane.

  • setw synchronize-panes

Convert pane into a window

  • ctrl + b,!

Copy Buffer

Aside from entering copy mode and pasting your most recent buffer, all these commands assume that you are already in copy mode.

Unless specified VIM keybindings are enable with set -g mode-keys vi. This section assumes you have this enabled. I would recommend adding this to your ~/.tmux.conf file.

Enter copy mode

  • ctrl + b,]

Exit copy mode

  • ctrl + b,esc
  • ctrl + b,q (VIM)

Navigate in copy mode

  • ctrl + ↑
  • ctrl + →
  • ctrl + ↓
  • ctrl + ←
  • h (VIM)
  • j (VIM)
  • k (VIM)
  • l (VIM)
Start selection

This VIM keybinding is custom and can be bound with

bind-key -T copy-mode-vi 'v' send -X begin-selection
(Link)
  • space
  • v (VIM)
Copy selection

This VIM keybinding is custom and can be bound with

bind-key -T copy-mode-vi 'y' send -X copy-selection-and-cancel
(Link)
  • enter
  • y (VIM)

Search window history

  • ?
  • / (VIM)

Goto top of history

  • g

Goto bottom of history

  • G

Goto next search result

  • n

Goto previous search result

  • N

Paste most recent buffer

  • ctrl + b,]

Open copy history to paste

  • ctrl + b,=

General

List all keybindings

  • ctrl + b,?

Show the time

  • ctrl + b,t

Show previous messages from TMUX

  • ctrl + b,~
Clearing window history

You can also bing this to a specific key with something like ctrl + l.

bind-key -n C-l send-keys C-l \; send-keys -R \; clear-history

(link)

  • tmux clear-history
  • clear-history
  • ctrl + b,ctrl + l (w/ config)
Sourcing your tmux.conf (link)
  • tmux source-file ~/.tmux.conf
  • tmux set -g prefix C-a
  • source-file ~/.tmux.conf
  • set -g prefix C-a

Getting Started

This section is included last because the purpose of this site is to help you remember how to do things you know. I’m not a TMUX expert too, so I was hesitant to include my config as I’m not an authority on TMUX. That said I want to help you learn if I can. If you have tips for making this section better, email me. If in doubt, getting started official guide is probably a good place to start.

Config

# Remove the ugly green default background.
set -g status-style bg=default

# Move the status bar to the top, since my nvim status bar is usually at the bottom.
set-option -g status-position top

# Enable mouse pane navigation and resizing.
set -g mouse on

# Set window and pane indexes. They default is 0.
# Jokes aside this is easier for navigation since 0 is on the other side of your keyboard.
set -g base-index 1
set-window-option -g pane-base-index 1

# Enable window renumbering. Deleting windows can leave gaps in the indexes.
# This option occationally adjusts window numbers so there are no gaps.
# Panes renumber automatically. `prefix + q` to see pane numbers.
set-option -g renumber-windows on

# Set new panes to open in current directory
bind c new-window -c "#{pane_current_path}"
bind '"' split-window -c "#{pane_current_path}"
bind % split-window -h -c "#{pane_current_path}"

# Change default options for choose-tree (`prefix + s`) to use index ordering.
# This is helpful for knowing the order of your sessions,
# which is used for going to the next/prev session.
bind s choose-tree -sZ -O index

Keybindings

# Setup `ctrl + b, r` to reload tmux config.
unbind r
bind r source-file ~/.tmux.conf

# Clear buffer history.
bind-key -n C-l send-keys C-l ; send-keys -R ; clear-history

# Vim navigation ----------------------------------------------------

# Enable vi like keybindings for navigating the buffer of a window.
set-window-option -g mode-keys vi

# Configure `v` and `y` to start and capture selection in 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

# Setup vim style pane selection (prefix + h/j/k/l).
bind h select-pane -L
bind j select-pane -D
bind k select-pane -U
bind l select-pane -R

# Setup vim style windows selection (atl + shift + right/left).
bind -n M-H previous-window
bind -n M-L next-window

# Arrow bindings (an alternative to vim) ----------------------------

# Use Alt-arrow keys without prefix key (-n) to switch panes.
bind M-Left select-pane -L
bind M-Right select-pane -R
bind M-Up select-pane -U
bind M-Down select-pane -D

# Use Shift-arrow keys without prefix (-n) key to switch windows.
bind -n S-Left previous-window
bind -n S-Right next-window

Plugins

Follow the installation guide for TMUX Plugin Manager.

set -g @plugin 'tmux-plugins/tpm'

# A sensible default package widely used by the community.
set -g @plugin 'tmux-plugins/tmux-sensible'

# Vim style `ctrl + h/j/k/l` navigation that works seemlessly between vim and tmux.
set -g @plugin 'christoomey/vim-tmux-navigator'

# Improved copying from within TMUX
# Not totally sure what all this one does, but it will escape ansi code.
set -g @plugin 'tmux-plugins/tmux-yank'

# Save and restore your session through system restarts.
set -g @plugin 'tmux-plugins/tmux-resurrect'

# Configure and use a great minimal status bar.
bind-key b set-option status
set -g @minimal-tmux-status "top"
set -g @plugin 'niksingh710/minimal-tmux-status'

# Initialize TMUX plugin manager (keep this line at the very bottom of tmux.conf).
run '~/.tmux/plugins/tpm/tpm'