Skip to content

Instantly share code, notes, and snippets.

@scottjwood
Forked from andreyvit/tmux.md
Last active November 12, 2023 12:27
Show Gist options
  • Save scottjwood/9067d332f2933a0c0c0e to your computer and use it in GitHub Desktop.
Save scottjwood/9067d332f2933a0c0c0e to your computer and use it in GitHub Desktop.
tmux cheatsheet

tmux cheat sheet

(CTRL-x means ctrl+x, ALT-x means alt+x)

Prefix key

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

# remap prefix to Control + a
set -g prefix CTRL-b
# bind 'CTRL-b CTRL-b' to type 'CTRL-b'
bind CTRL-b send-prefix
unbind CTRL-b

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.

Getting help

Display a list of keyboard shortcuts:

CTRL-b ?

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, CTRL-u, CTRL-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 CTRL-b :something (or added to ~/.tmux.conf).

Managing sessions

Creating a session:

tmux new-session -s work

Create a new session that shares all windows with an existing session, but has its own separate notion of which window is current:

tmux new-session -s work2 -t work

Attach to a session:

tmux attach -t work

Detach from a session: CTRL-b d.

Switch between sessions:

CTRL-b (          previous session
CTRL-b )          next session
CTRL-b L          ‘last’ (previously used) session
CTRL-b s          choose a session from a list

Other:

CTRL-b $          rename the current session
CTRL-b

Managing windows

Create a window:

CTRL-b c          create a new window

Switch between windows:

CTRL-b 1 ...      switch to window 1, ..., 9, 0
CTRL-b 9
CTRL-b 0
CTRL-b p          previous window
CTRL-b n          next window
CTRL-b l          ‘last’ (previously used) window
CTRL-b w          choose window from a list

Switch between windows with a twist:

CTRL-b ALT-n        next window with a bell, activity or
               content alert
CTRL-b ALT-p        previous such window

Other:

CTRL-b ,          rename the current window
CTRL-b &          kill the current window

Managing split panes

Creating a new pane by splitting an existing one:

CTRL-b "          split vertically (top/bottom)
CTRL-b %          split horizontally (left/right)

Switching between panes:

CTRL-b left       go to the next pane on the left
CTRL-b right      (or one of these other directions)
CTRL-b up
CTRL-b down
CTRL-b o          go to the next pane (cycle through all of them)
CTRL-b ;          go to the ‘last’ (previously used) pane

Moving panes around:

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

Resizing panes:

CTRL-b ALT-up, CTRL-b ALT-down, CTRL-b ALT-left, CTRL-b ALT-right
               resize by 5 rows/columns
CTRL-b CTRL-up, CTRL-b CTRL-down, CTRL-b CTRL-left, CTRL-b CTRL-right
               resize by 1 row/column

Applying predefined layouts:

CTRL-b ALT-1        switch to even-horizontal layout
CTRL-b ALT-2        switch to even-vertical layout
CTRL-b ALT-3        switch to main-horizontal layout
CTRL-b ALT-4        switch to main-vertical layout
CTRL-b ALT-5        switch to tiled layout
CTRL-b space      switch to the next layout

Other:

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

Other config file settings

Force a reload of the config file on CTRL-b r:

unbind r
bind r source-file ~/.tmux.conf
@scottjwood
Copy link
Author

This was forked from https://gist.github.com/andreyvit/2921703, I just changed the shortcut back to the default.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment