Skip to content

Instantly share code, notes, and snippets.

@wgao19
Forked from andreyvit/tmux.md
Last active June 7, 2019 03:21
Show Gist options
  • Save wgao19/b73830e90b3210d1985b869a25a2d2bf to your computer and use it in GitHub Desktop.
Save wgao19/b73830e90b3210d1985b869a25a2d2bf to your computer and use it in GitHub Desktop.
tmux cheatsheet

tmux cheat sheet

Prefix key

The default prefix is C-b. If you (or your muscle memory) prefer something else, 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

Configurations

# don't allow tmux to rename the window based on commands running
set-window-option -g allow-rename off

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.

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: prefix d.

Switch between sessions:

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

Other:

prefix $          rename the current session

Managing windows

Create a window:

prefix c          create a new window

Switch between windows:

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

Switch between windows with a twist:

   prefix M-n       next window with a bell, activity or content alert    prefix M-p       previous such window

Other:

prefix ,          rename the current window
prefix &          kill the current window

Managing split panes

Creating a new pane by splitting an existing one:

prefix "          split vertically (top/bottom)
prefix %          split horizontally (left/right)

Switching between panes:

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

Moving panes around:

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

Resizing panes:

prefix M-up, prefix M-down, prefix M-left, prefix M-right
                  resize by 5 rows/columns
prefix C-up, prefix C-down, prefix C-left, prefix C-right
                  resize by 1 row/column

Resizing panes (continued):

:resize-pane -D (Resizes the current pane down)
:resize-pane -U (Resizes the current pane upward)
:resize-pane -L (Resizes the current pane left)
:resize-pane -R (Resizes the current pane right)
:resize-pane -D 10 (Resizes the current pane down by 10 cells)
:resize-pane -U 10 (Resizes the current pane upward by 10 cells)
:resize-pane -L 10 (Resizes the current pane left by 10 cells)
:resize-pane -R 10 (Resizes the current pane right by 10 cells)

Applying predefined layouts:

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

Other:

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

Misc issues

Open clock

prefix t

Resize usable region

When you attach to a session with a smaller usable area, that session sets the window's usable area and the other window is going to be resized. This solution "goes around" the problem by detaching other sessions when attaching, maybe should set this in alias:

tmux attach -d

More approaches here

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