Skip to content

Instantly share code, notes, and snippets.

@vkroz
Forked from MohamedAlaa/tmux-cheatsheet.markdown
Last active July 6, 2021 15:21
Show Gist options
  • Save vkroz/af1079b921bfc5fab6fd9a92cd11ddde to your computer and use it in GitHub Desktop.
Save vkroz/af1079b921bfc5fab6fd9a92cd11ddde to your computer and use it in GitHub Desktop.
tmux shortcuts & cheatsheet

tmux for humans

How to get

If tmux is not installed, then install it or buid from sources.

Installing

  • MacOS: brew install tmux
  • CentOS family: yum install tmux
  • Ubuntu family: apt-get install tmux

Command line options

Starting

# Start new
tmux

# Start new using iTerm2 as terminal device (on MacOS)
tmux -CC

# Reattach to existing session - any of the following commands
tmux a  
tmux at
tmux attach

# Start new with session name
tmux new -s myname

# Attach to named:
tmux a -t myname

Sessions

List sessions:

tmux ls

kill session:

tmux kill-session -t myname

Kill all the tmux sessions:

tmux ls | grep : | cut -d. -f1 | awk '{print substr($1, 0, length($1)-1)}' | xargs kill

Inside terminal session

Within terminal session tmux is controlled by keyboard commands. To invoke any command - hit command prefix (default ctrl+b) followed by command. E.g. to et help press ctrl-b and then ?. You'll get list of all tmux commmands and key bindings

Sessions

:new<CR>  new session
s  list sessions
$  name session
d  detach client (exit from tmux)

To execute command press prefix followed by corresponding key. Default command prefix ctrl+b

Windows (tabs)

c  create window
w  list windows
n  next window
p  previous window
f  find window
,  name window
&  kill window

Panes (splits)

%       vertical split
"       horizontal split

o       Swap panes
q       Show pane numbers
x       Kill pane
z       Maximize pane to whole windows / restore pane size
space   Toggle between layouts
q       Show pane numbers, when the numbers show up type the key to goto that pane)
{       Move the current pane left
}       Move the current pane right
z       toggle pane zoom

Resizing Panes

How to resize panes of current screen layout

: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 20      Resizes the current pane down by 20 cells
:resize-pane -U 20      Resizes the current pane upward by 20 cells
:resize-pane -L 20      Resizes the current pane left by 20 cells
:resize-pane -R 20      Resizes the current pane right by 20 cells
:resize-pane -t 2 20    Resizes the pane with the id of 2 down by 20 cells
:resize-pane -t -L 20   Resizes the pane with the id of 2 left by 20 cells

Misc

t  big clock
?  list shortcuts
:  prompt

Configurations Options:

# Mouse support - set to on if you want to use the mouse
* setw -g mode-mouse off
* set -g mouse-select-pane off
* set -g mouse-resize-pane off
* set -g mouse-select-window off

# Set the default terminal mode to 256color mode
set -g default-terminal "screen-256color"

# enable activity alerts
setw -g monitor-activity on
set -g visual-activity on

# Center the window list
set -g status-justify centre

# Maximize and restore a pane
unbind Up bind Up new-window -d -n tmp \; swap-pane -s tmp.1 \; select-window -t tmp
unbind Down
bind Down last-window \; swap-pane -s tmp.1 \; kill-window -t tmp

Resources:

Building from sources

Why it is needed? Because some distros (e.g. CentOS) comes with old tmux which lacks cool features, such as integration with Mac iTerm2 etc. Check your tmux version: tmux -V. If the version you get is less then 2.2, then do yourself a favor and build a latest version from the sources.

  1. Get and build libevent library (tmux depends on it)
wget https://github.com/libevent/libevent/releases/download/release-2.1.8-stable/libevent-2.1.8-stable.tar.gz
tar xzf libevent-2.1.8-stable.tar.gz && cd libevent-2.1.8-stable
./configure && make
sudo make install

> /usr/local/lib
> libtool: finish: PATH="/sbin:/bin:/usr/sbin:/usr/bin:/sbin" ldconfig -n /usr/local/lib
> ----------------------------------------------------------------------
> Libraries have been installed in:
>    /usr/local/lib

# Make library linkable
ldconfig -n /usr/local/lib
  1. Get and build tmux. 2.8 is latest build in Jan 2019, check if there is newer one now
wget https://github.com/tmux/tmux/releases/download/2.8/tmux-2.8.tar.gz
tar xzf tmux-2.8.tar.gz && cd tmux-2.8
./configure && make
sudo make install
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment