# Tmux Cheatsheet A comprehensive guide to tmux commands, shortcuts, and usage. ## Sessions ### Creating Sessions **Start a new session** ```bash tmux tmux new tmux new-session ``` **Start a new session or attach to an existing session named *mysession*** ```bash tmux new-session -A -s mysession ``` **Start a new session with the name *mysession*** ```bash tmux new -s mysession ``` **Start a new session with the name *mysession* and window *mywindow*** ```bash tmux new -s mysession -n mywindow ``` ### Managing Sessions **Kill/delete the current session** - Command: `kill-session` **Kill/delete session *mysession*** ```bash tmux kill-ses -t mysession tmux kill-session -t mysession ``` **Kill/delete all sessions but the current** ```bash tmux kill-session -a ``` **Kill/delete all sessions but *mysession*** ```bash tmux kill-session -a -t mysession ``` **Rename session** - Shortcut: `Ctrl+b` `$` **Detach from session** - Shortcut: `Ctrl+b` `d` **Detach others on the session (Maximize window by detach other clients)** - Command: `attach -d` ### Viewing and Attaching Sessions **Show all sessions** ```bash tmux ls tmux list-sessions ``` - Shortcut: `Ctrl+b` `s` **Attach to last session** ```bash tmux a tmux at tmux attach tmux attach-session ``` **Attach to a session with the name *mysession*** ```bash tmux a -t mysession tmux at -t mysession tmux attach -t mysession tmux attach-session -t mysession ``` ### Navigating Sessions **Session and Window Preview** - Shortcut: `Ctrl+b` `w` **Move to previous session** - Shortcut: `Ctrl+b` `(` **Move to next session** - Shortcut: `Ctrl+b` `)` ## Windows ### Creating and Managing Windows **Create window** - Shortcut: `Ctrl+b` `c` **Rename current window** - Shortcut: `Ctrl+b` `,` **Close current window** - Shortcut: `Ctrl+b` `&` **List windows** - Shortcut: `Ctrl+b` `w` ### Navigating Windows **Previous window** - Shortcut: `Ctrl+b` `p` **Next window** - Shortcut: `Ctrl+b` `n` **Switch/select window by number** - Shortcut: `Ctrl+b` `0` ... `9` **Toggle last active window** - Shortcut: `Ctrl+b` `l` ### Reordering Windows **Reorder window, swap window number 2(src) and 1(dst)** - Command: `swap-window -s 2 -t 1` **Move current window to the left by one position** - Command: `swap-window -t -1` **Move window from source to target** ``` move-window -s src_ses:win -t target_ses:win movew -s foo:0 -t bar:9 movew -s 0:0 -t 1:9 ``` **Reposition window in the current session** ``` move-window -s src_session:src_window movew -s 0:9 ``` **Renumber windows to remove gap in the sequence** ``` move-window -r movew -r ``` ## Panes ### Creating and Managing Panes **Split the current pane with a vertical line to create a horizontal layout** - Shortcut: `Ctrl+b` `%` - Command: `split-window -h` **Split the current pane with a horizontal line to create a vertical layout** - Shortcut: `Ctrl+b` `"` - Command: `split-window -v` **Join two windows as panes (Merge window 2 to window 1 as panes)** - Command: `join-pane -s 2 -t 1` **Move pane from one window to another (Move pane 1 from window 2 to pane after 0 of window 1)** - Command: `join-pane -s 2.1 -t 1.0` **Close current pane** - Shortcut: `Ctrl+b` `x` **Convert pane into a window** - Shortcut: `Ctrl+b` `!` ### Navigating Panes **Toggle last active pane** - Shortcut: `Ctrl+b` `;` **Switch to pane to the direction** - Shortcuts: - `Ctrl+b` `↑` - `Ctrl+b` `↓` - `Ctrl+b` `→` - `Ctrl+b` `←` **Switch to next pane** - Shortcut: `Ctrl+b` `o` **Show pane numbers** - Shortcut: `Ctrl+b` `q` **Switch/select pane by number** - Shortcut: `Ctrl+b` `q` `0` ... `9` ### Moving Panes **Move the current pane left** - Shortcut: `Ctrl+b` `{` **Move the current pane right** - Shortcut: `Ctrl+b` `}` ### Resizing Panes **Resize current pane height (holding second key is optional)** - Shortcuts: - `Ctrl+b` `↑` (or `Ctrl+b` `Ctrl+↑`) - `Ctrl+b` `↓` (or `Ctrl+b` `Ctrl+↓`) **Resize current pane width (holding second key is optional)** - Shortcuts: - `Ctrl+b` `→` (or `Ctrl+b` `Ctrl+→`) - `Ctrl+b` `←` (or `Ctrl+b` `Ctrl+←`) ### Pane Options **Toggle synchronize-panes (send command to all panes)** - Command: `setw synchronize-panes` **Toggle between pane layouts** - Shortcut: `Ctrl+b` `Spacebar` **Toggle pane zoom** - Shortcut: `Ctrl+b` `z` ## Copy Mode ### Configuration **Use vi keys in buffer** - Command: `setw -g mode-keys vi` ### Entering and Exiting Copy Mode **Enter copy mode** - Shortcut: `Ctrl+b` `[` **Enter copy mode and scroll one page up** - Shortcut: `Ctrl+b` `PgUp` **Quit mode** - Shortcut: `q` ### Navigation **Go to top line** - Shortcut: `g` **Go to bottom line** - Shortcut: `G` **Scroll up** - Shortcut: `↑` **Scroll down** - Shortcut: `↓` **Move cursor left** - Shortcut: `h` **Move cursor down** - Shortcut: `j` **Move cursor up** - Shortcut: `k` **Move cursor right** - Shortcut: `l` **Move cursor forward one word at a time** - Shortcut: `w` **Move cursor backward one word at a time** - Shortcut: `b` ### Searching **Search forward** - Shortcut: `/` **Search backward** - Shortcut: `?` **Next keyword occurrence** - Shortcut: `n` **Previous keyword occurrence** - Shortcut: `N` ### Selection and Copying **Start selection** - Shortcut: `Spacebar` **Clear selection** - Shortcut: `Esc` **Copy selection** - Shortcut: `Enter` **Paste contents of buffer_0** - Shortcut: `Ctrl+b` `]` ### Buffer Management **Display buffer_0 contents** - Command: `show-buffer` **Copy entire visible contents of pane to a buffer** - Command: `capture-pane` **Show all buffers** - Command: `list-buffers` **Show all buffers and paste selected** - Command: `choose-buffer` **Save buffer contents to *buf.txt*** - Command: `save-buffer buf.txt` **Delete buffer_1** - Command: `delete-buffer -b 1` ## Miscellaneous **Enter command mode** - Shortcut: `Ctrl+b` `:` **Set OPTION for all sessions** - Command: `set -g OPTION` **Set OPTION for all windows** - Command: `setw -g OPTION` **Enable mouse mode** - Command: `set mouse on` ## Help **List key bindings (shortcuts)** ```bash tmux list-keys ``` - Command: `list-keys` - Shortcut: `Ctrl+b` `?` **Show every session, window, pane, etc...** ```bash tmux info ``` --- ## Quick Reference ### Default Prefix Key The default tmux prefix is `Ctrl+b`. All shortcuts require pressing this first, then the specified key. ### Common Workflow 1. Start a session: `tmux new -s myproject` 2. Create windows: `Ctrl+b` `c` 3. Split panes: `Ctrl+b` `%` or `Ctrl+b` `"` 4. Navigate: `Ctrl+b` `arrow keys` 5. Detach: `Ctrl+b` `d` 6. Reattach: `tmux attach -t myproject`