Tmux Cheatsheet

Ctrl+a Ctrl+a : Go to head of the command line

w : Move cursor forward one word at a time

b : Move cursor backward one word at a time

Session

  • Ctrl+a :new -s mysession

  • Ctrl+a d : Detach from session (exit tmux)

  • Ctrl+a s : Show all sessions

  • Ctrl+a $ : Rename session

  • Ctrl+a :kill-session -t XXX

  • Ctrl+a ( : Move to previous session

  • Ctrl+a ) : Move to next session

  • Ctrl+a w : Show all sessions and windows

Window (quick switch)

  • Ctrl+a c : Create window

  • Ctrl+a , : Rename current windows

  • Ctrl+a & : Close current window

  • Ctrl+a n : Next window

  • Ctrl+a 0…9 : Show all sessions

  • Ctrl+a $ : Switch/select window by number

  • Ctrl+a :swap-window -s 2 -t 1 Reorder window, swap window number 2(src) and 1(dst)

  • Ctrl+a :swap-window -t -1 Move current window to the left by one position

Panes

  • Ctrl+a % : Split pane vertically

  • Ctrl+a “ : Split pane horizontally

  • Ctrl+a [arrow key] : Switch to pane to the direction

  • Ctrl+a ; : Toggle last active pane

  • Ctrl+a o : Switch to next pane

  • Ctrl+a { : Move the current pane left

  • Ctrl+a } : Move the current pane right

  • Ctrl+a x : Close current pane

  • Ctrl+a ! : Convert pane into a window

  • Ctrl+a z : Toggle pane zoom

  • Ctrl+a+[arrow key] : Resize current pane size

  • Ctrl+a q : Show pane numbers

  • Ctrl+a q 0…9 : Switch/select pane by number

.tmux.conf

# Set the default TERM
set -g default-terminal screen

# Update the TERM variable of terminal emulator when creating a new session or attaching a existing session
# (Note: the space is needed so it doesn't merge with previous variables)"
set-option -ga update-environment " TERM"

# Determine if we should enable 256-colour support
if "[[ ${TERM} =~ 256color || ${TERM} == fbterm ]]" 'set -g default-terminal screen-256color'

# Ring the bell if any background window rang a bell
set -g bell-action any

# Update custom sent env vars
# https://babushk.in/posts/renew-environment-tmux.html
# https://stackoverflow.com/a/9833996
set-option -ga update-environment " LC_USER_KEYNAME \
                                    LC_USER_NAME \
                                    LC_USER_EMAIL \
                                    LC_USER \
                                    LC_USER_WORKSPACE"

# color scheme (styled as vim-powerline)
set -g status-left-length 52
set -g status-right-length 451
set -g status-fg white
set -g status-bg colour234
set -g pane-border-style fg=colour245
set -g pane-active-border-style fg=colour39
set -g message-style fg=colour16,bg=colour221,bold
set -g status-left '#[fg=colour235,bg=colour252,bold]#S #[fg=colour252,bg=colour238,nobold]#[fg=colour245,bg=colour238,bold] #(whoami)#[fg=colour238,bg=colour234,nobold]'
set -g window-status-format "#[fg=colour235,bg=colour252,bold] #I #W "
set -g window-status-current-format "#[fg=colour234,bg=colour39]#[fg=colour235,bg=colour39,noreverse,bold] #I: #W #[fg=colour39,bg=colour234,nobold]"

# Bigger history
set -g history-limit 10000

# Set default shell to $SHELL
set-option -g default-shell $SHELL

# Setting the prefix from C-b to C-a
set -g prefix C-a

# Free the original Ctrl-b prefix keybinding
unbind C-b

#setting the delay between prefix and command
set -sg escape-time 0

# Ensure that we can send Ctrl-A to other apps
bind C-a send-prefix

# Set the base index for windows to 1 instead of 0
set -g base-index 1

# Set the base index for panes to 1 instead of 0
setw -g pane-base-index 1

# Reload the file with Prefix r
bind r source-file ~/.tmux.conf \; display "Reloaded!"

# splitting panes
bind | split-window -h
bind - split-window -v

# Pane resizing
bind -r H resize-pane -L 5
bind -r J resize-pane -D 5
bind -r K resize-pane -U 5
bind -r L resize-pane -R 5

# Create new window next to the current one
bind n new-window -a

# mouse support - set to on if you want to use the mouse
set-option -g mouse on

# 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

# enable vi keys.
setw -g mode-keys vi

# Vim clipboard bindings
unbind [
bind Escape copy-mode
unbind p
bind p paste-buffer
bind-key -T copy-mode-vi v send-keys -X begin-selection
bind-key -T copy-mode-vi y send-keys -X copy-selection

# Tmux clear history
bind C-k send-keys -R \; clear-history \; send-keys C-l
bind C-l send-keys 'C-l'

bind-key Y command-prompt -p 'save history to filename:' -I '~/tmux.history' 'capture-pane -S - ; save-buffer %1 ; delete-buffer'

bind -n S-Left previous-window
bind -n S-Right next-window

set -g @plugin 'tmux-plugins/tpm'
set -g @plugin 'tmux-plugins/tmux-resurrect'
set -g @plugin 'christoomey/vim-tmux-navigator'

set-environment -g TMUX_PLUGIN_MANAGER_PATH '~/.tmux/plugins/'
run -b '~/.tmux/plugins/tpm/tpm'
Xiyu Zhai
Software Engineer

My research interests include robotics, multi-agent control and graphics.