tmux new -s mysession echo This is session 1 ... # press prefix + d to detach tmux attach -t mysession
tmux new -s work tmux new -s play tmux new -s test tmux ls tmux kill-session -t test
# detach, close tab, open new tab tmux ls # server still running tmux attach # session still alive
prefix + c # new window prefix + , # rename window # name: code, logs, git, docs, shell
prefix + n # next window prefix + p # prev window prefix + 0-9 # jump to window N prefix + l # last window
prefix + c tail -f /var/log/syslog # switch away, switch back — still tailing
prefix + % # vertical split (left/right) prefix + " # horizontal split (top/bottom) prefix + arrows # move between panes
prefix + z # zoom into current pane prefix + z # unzoom
prefix + x # close pane # notice layout shift — learn to live with it
# window 1: prefix + % twice, prefix + " once # window 2: prefix + c
prefix + ! # break pane into new window
prefix + } # move pane right
prefix + { # move pane left
tmux new -s proj # build layout, rename, detach, reattach tmux rename-session -t 0 'myproject'
seq 1 1000 prefix + [ # enter copy mode # arrow keys or PgUp to scroll
prefix + [ # navigate, Space to start selection # Enter/y to copy, prefix + ] to paste
prefix + [ /keyword # search forward ?keyword # search backward n/N # next/prev match
prefix + : set -g mode-keys vi # now use h/j/k/l in copy mode
tmux new -s a # add windows + panes, then: tmux new -s b tmux new -s c
prefix + s # list/switch sessions prefix + $ # rename session tmux kill-session -t name
# speed drill — muscle memory # create session → windows → panes → detach
tmux new -s dojo # window 1: prefix + % (editor + shell) # window 2: htop # window 3: git status
session → window → pane → copy → paste # full cycle 10x
prefix + 0-9 # window jump prefix + arrows # pane jump # target: < 3s
prefix + ? # list all keys # find your weak spots, drill them
# ~/.tmux.conf set -g prefix C-a unbind C-b bind C-a send-prefix set -g mouse on # reload: prefix + : source ~/.tmux.conf
set -g prefix C-a unbind C-b bind C-a send-prefix # now use C-a instead of C-b
prefix + space # cycle layouts even-horizontal, even-vertical, main-horizontal, main-vertical, tiled
prefix + space until main-horizontal # resize: prefix + Alt+arrows
prefix + z # zoom pane prefix + Alt+arrows # resize split
set -g status-right '#H | #(uptime | cut -d, -f2) | %H:%M'
setw -g window-status-current-style bg=green,fg=black
set -g status-right '#(date "+%%Y-%%m-%%d %%H:%%M")'
bind -n M-h select-pane -L bind -n M-j select-pane -D bind -n M-k select-pane -U bind -n M-l select-pane -R
bind r source-file ~/.tmux.conf \; display 'reloaded' bind -n M-1 select-window -t 1
# delete ~/.tmux.conf, rebuild from memory cat ~/.tmux.conf
tmux list-keys | less # find commands you never used
prefix + : resize-pane -L 10 prefix + : join-pane -s 0 prefix + : swap-pane -U prefix + : setw synchronize-panes on
# bind them in .tmux.conf: bind S command-prompt -p 'session:' 'new-session -s "%%"'
set -g mouse on # click panes, drag borders, scroll wheel
set -g window-status-format '#[fg=colour240]#I:#W' set -g window-status-current-format '#[fg=colour46,bold]#I:#W'
set -g default-terminal 'tmux-256color' set -ga terminal-overrides ',xterm-256color:Tc'
mv ~/.tmux.conf ~/.tmux.conf.bak touch ~/.tmux.conf # rebuild: prefix, mouse, vim nav, colors, status
# target: < 20 minutes # no peeking at notes
# if you can't explain it, you don't own it # annotate every line in ~/.tmux.conf
tmux new -s proj -d tmux split-window -h -t proj tmux send-keys -t proj 'vim' Enter
tmux new -s proj -d -c ~/project tmux attach -t proj
tmux send-keys -t proj 'ls -la' Enter
#!/bin/bash if tmux has-session -t dev 2>/dev/null; then tmux attach -t dev else tmux new -s dev -c ~/project fi
chmod +x ~/bin/dev ~/bin/dev # always correct result
pip install tmuxp
# ~/.tmuxp/project.yaml:
session_name: project
windows:
- editor:
layout: main-vertical
panes:
- vim
- shell
- server: npm start
- git: git status
tmuxp load ~/.tmuxp/project.yaml tmuxp freeze > ~/.tmuxp/project.yaml
tmuxp freeze -y > new_session.yaml
# ~/.bashrc or ~/.zshrc:
ta() { tmux has-session -t "$1" 2>/dev/null && tmux attach -t "$1" || tmux new -s "$1"; }
# ~/.bashrc: if [ -n "$SSH_CLIENT" ] && [ -z "$TMUX" ]; then tmux attach-session -t main || tmux new-session -s main fi
set -g update-environment 'SSH_AUTH_SOCK SSH_CLIENT' # or: tmux setenv -g VAR value
prefix + : setw synchronize-panes on # type in all panes at once setw synchronize-panes off
# bind to key: bind S setw synchronize-panes \; display 'sync toggled'
tmux capture-pane -t 0 -p > /tmp/output.txt tmux capture-pane -t 0 -S -1000 | tee output.txt
ssh remote tmux new -s work tail -f /var/log/app.log # close SSH, reconnect: job still running
tmux attach -t session # terminal 1 tmux attach -d -t session # terminal 2 takes over
docker run -it --name tmux-test ubuntu bash apt update && apt install tmux -y
# dev: new-session + split + send-keys # monitor: htop, logs, ping in panes # switcher: tmux switch-client -t name
# run script twice — must not error # add has-session checks
# speed drill time ( tmux new -s test -d && sleep 0.1 && tmux kill-session -t test )
git clone https://github.com/tmux-plugins/tpm ~/.tmux/plugins/tpm # ~/.tmux.conf: set -g @plugin 'tmux-plugins/tpm' # press prefix + I to install
set -g @plugin 'tmux-plugins/tmux-yank' # copy mode: y copies to system clipboard
set -g @plugin 'tmux-plugins/tmux-open' # copy mode: O opens URL under cursor
set -g @plugin 'tmux-plugins/tmux-resurrect' # save: prefix + Ctrl+s # restore: prefix + Ctrl+r tmux kill-server # restart, restore — everything back
set -g @plugin 'tmux-plugins/tmux-continuum' set -g @continuum-restore 'on' set -g @continuum-save-interval '15'
set -g @plugin 'christoomey/vim-tmux-navigator' # use C-h/j/k/l to move between vim and tmux panes
set -g @plugin 'sainnhe/tmux-fzf' # prefix + Ctrl-f for fuzzy session switch
prefix + : display-popup prefix + : display-popup -E # interactive prefix + : display-popup -w 80% -h 80%
tmux pipe-pane -o 'cat >> /tmp/tmux.log' tmux pipe-pane # stop logging
tmux -L foo new -s x # custom socket tmux list-sockets
# editor: 75% main + 25% side # server: logs tailed # git: status + diff panes
# every action through tmux # count how many times you reach for new tab — retrain
tmux new -s monitor tmux split-window -h tmux split-window -v tmux select-pane -t 0 # htop | journalctl -f | df -h | ping localhost
# one tmux window per host # synchronize-panes for parallel commands
set -g prefix2 C-a # secondary prefix # double-tap prefix to reach inner tmux
tmux new-session -d -s base tmux new-session -d -s child -t base # windows shared across group
# comment every line: why, not what # remove anything you don't use daily
# kitty, xterm, alacritty — all should look same # SSH in, verify colors and keys
man tmux | less # search for commands you use daily — find hidden flags
apt install tmux / brew install tmux tmux -V
# prefix, vim nav, mouse, colors, status, reload, base-index 1
tmux new -s dev -d tmux split-window -h -t dev tmux split-window -v -t dev.0 tmux send-keys -t dev 'vim' Enter
# plugins installed, save/restore working, auto-save on
prefix + [ → /search → Space → y → prefix + ]
htop | journalctl -f | df -h | ping localhost
prefix + Ctrl+s tmux kill-server # restart, prefix + Ctrl+r
prefix + : # fix via command mode, no config reload list-keys, show-options, resize-pane