Skip to content

Instantly share code, notes, and snippets.

@henri
Last active March 7, 2025 10:22
Show Gist options
  • Save henri/0a4ff6192136660c83bfa0c3df56211d to your computer and use it in GitHub Desktop.
Save henri/0a4ff6192136660c83bfa0c3df56211d to your computer and use it in GitHub Desktop.
tmux cheatsheet
# sorce in other config files
# source-file ~/.conf/tmux/tmux_reset.conf
# bind alt arrorw keys for switching panes
bind -n M-Left select-pane -L
bind -n M-Right select-pane -R
bind -n M-Up select-pane -U
bind -n M-Down select-pane -D
# start window number at 1 rather than zero (good if you do not have a numpad on your keyboard)
set -g base-index 1
# allow different clients to have different sized windows (same session)
# to really make use of this - you will want to check out this link (scroll to the bottom) :
# https://mutelight.org/practical-tmux
setw -g aggressive-resize on
# notifications
#setw -g monitor-activity on
#set -g visual-activity on
# current window highlighting
set-window-option -g window-status-current-bg yellow
# set status window update interval
# set -g status-interval 3
# switch panes with the mouse
#set-option -g mouse-select-pane on
set -g mouse on
# setup less-insane scrolling
set -g terminal-overrides 'xterm*:smcup@:rmcup@'
# setup m key to toggle the mouse off and back on (great if you want to use the mouse for copy and paste)
bind m set-option mouse\; display-message "Mouse is now #{?mouse,on,off}"
# setup X to enable syncronize-panes (toggle command)
bind-key X set-window-option synchronize-panes\; display-message "synchronize-panes is now #{?pane_synchronized,on,off}"
# status bar position
# set -g status-justify left
# set -g status-left-length 200
# set -g status-right-length 200
# set -g status-position top
# set -g status-style 'bg=#1e1e2e' # transparent
# don't exit from tmux when closing session
# set -g detach-on-destroy off
# increase history
# set -g history-limit 1000000
# system clipboard
set -g set-clipboard on
# when using bind-key and w only show current session windows and panes (modern tmux versions show all sessions in the picker)
bind-key -r -T prefix w run-shell 'tmux choose-tree -Nwf"##{==:##{session_name},#{session_name}}"'
# set-option -g default-terminal 'screen-256color'
# set-option -g terminal-overrides ',xterm-256color:RGB'
# set -g pane-active-border-style 'fg=magenta,bg=default'
# set -g pane-border-style 'fg=brightblack,bg=default'
# show various commands
tmux list-commands
# list tmux sessions
tmux list-sessions
# create new session with specific name
tmux new -s <my-session-name>
# rename a session
tmux rename-session -t <old-name> <new-name>
# attach to a session (works with some versions)
tmux attach -t [session name]
# start a session with name and run command
tmux new -s <sesion-name> '<command-to-run>'
# kill session by name / number
tmux kill-session -t <session-name>
# attach to a session by name (works with others)
tmux attach -t [session-name]
# attach to a session by number
tmux attach -t [session-number]
# list attached clients
tmux list-sessions
# reload the tmux config:
tmux source-file ~/.tmux.conf
# show help / get help / show current keybindings
Ctrl+b ?
# rename current window
Ctrl+b ,
# redraw the session (specificially the client)
Ctrl+b r
:refresh
# rename session
tmux rename-session <new-name>
# switch between last used panes / windows / sessions
# - use 'q' or 'esc' to exit back to current pane / window / session (as expected)
# - use arrow keys to collaps or expand the lists / nesting (as expected)
# - use '/' to start search (as expected)
Ctrl+b l
# show list of windows / sessions (pop up switcher)
Ctrk+b w
# merge a window into a pane (it works)
join-pane -s 2 -t 1
# choose tree with sessions collaposed (newer versions of tmux)
choose-tree -s
# basic tmux commands:
Ctrl+b " — split pane horizontally
Ctrl+b % — split pane vertically
Ctrl+b arrow key — switch pane
Ctrl+b z — zoom pane / unzoom pane
Ctrl+b } — swap current pane with the pane from the left (using mouse mode equivilent to up)
Ctrl+b { — swap current pane with the page from the right (using mouse mode eqivilent to down)
Hold Ctrl+b, don’t release it and hold one of the arrow keys — resize pane.
Ctrl+b c — (c)reate a new window
Ctrl+b n — move to the (n)ext window
Ctrl+b p — move to the (p)revious window
Ctrl+b [0..9] — jump to window
Ctrl+b Alt+1 — evenly distribute panes of current window horizontally
Ctrl+b Alt+2 — evenly distribute panes of current window vertically
Ctrl-b space — cycle via available layouts (no gareentee of saving current layout)
# enable / disable sending command to all panes within a window (this is a toggle command)
Ctrl-b :setw synchronize-panes
# -- Helpful Links -- #
# https://lukaszwrobel.pl/blog/tmux-tutorial-split-terminal-windows-easily/
renaming tmux session :
quick: prefix, then dollar sign:
Ctrl+b $
long way: prefix, then colon:
Ctrl+b :
rename-session [-t current-name] [new-name]
If the current session name (-t current-name) is not specified, the currently attached session will be renamed.
By default the session name will be in brackets in the lower left corner of tmux.
You can list all sessions and switch between them with:
Ctrl+b s
# well laid out cheatsheet for basic tmux navigation :
https://www.linode.com/docs/guides/persistent-terminal-sessions-with-tmux/
# copy and paste
Ctrl+b [ # enter visual mode
Ctrl+b ] # paste
# visual editing keyboard shortcuts works with mouse mode on or off
+-------------------+--------------------+---------------+
| Action | emacs | vi |
+-------------------+--------------------+---------------+
| move character | Up Down Left Right | j k h l |
| move line | Ctrl-Up Ctrl-Down | Ctrl+Y Ctrl+E |
| move whole screen | PageUp PageDown | Ctrl+B Ctrl+F |
| search | Ctrl+S | / |
| start selection | Ctrl+Space | Space |
| copy selection | Ctrl+W | Enter |
| clear selection | Ctrl+G | Escape |
| exit copy mode | Escape | q |
+-------------------+--------------------+---------------+
# if you have mouse mode enabled you can use that to select and copy in one step
# remove keybindings
unbind-key -a
# reinsert regular tmux keys
bind ^X lock-server
bind ^C new-window -c "$HOME"
bind ^D detach
bind * list-clients
bind H previous-window
bind L next-window
bind r command-prompt "rename-window %%"
bind R source-file ~/.config/tmux/tmux.conf
bind ^A last-window
bind ^W list-windows
bind w list-windows
bind z resize-pane -Z
bind ^L refresh-client
bind l refresh-client
bind | split-window
bind s split-window -v -c "#{pane_current_path}"
bind v split-window -h -c "#{pane_current_path}"
bind '"' choose-window
bind h select-pane -L
bind j select-pane -D
bind k select-pane -U
bind l select-pane -R
bind -r -T prefix , resize-pane -L 20
bind -r -T prefix . resize-pane -R 20
bind -r -T prefix - resize-pane -D 7
bind -r -T prefix = resize-pane -U 7
bind : command-prompt
bind * setw synchronize-panes
bind P set pane-border-status
bind c kill-pane
bind x swap-pane -D
bind S choose-session
bind R source-file ~/.config/tmux/tmux.conf
bind K send-keys "clear"\; send-keys "Enter"
bind-key -T copy-mode-vi v send-keys -X begin-selection
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment