Skip to content

Instantly share code, notes, and snippets.

@pl77
Forked from andreyvit/tmux.md
Last active January 9, 2020 17:15
Show Gist options
  • Save pl77/5db15c78c826982bef2cecf0626b367b to your computer and use it in GitHub Desktop.
Save pl77/5db15c78c826982bef2cecf0626b367b to your computer and use it in GitHub Desktop.
tmux cheatsheet

tmux cheat sheet

Prefix key

The default prefix is C-b. I'm going to assume that Ctrl-b is your prefix.

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, 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 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 C-down, Ctrl-b C-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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment