TMUX Cheatsheet


A handy tmux cheatsheet for developers. It covers the most common commands and shortcuts for managing terminal sessions efficiently.


Starting tmux

  • Start a new session:
    tmux
  • Start a named session:
    tmux new -s <session-name>

Detaching and Reattaching

  • Detach from the current session:
    Ctrl + b then d
    (Hold Ctrl, press b, release both, then press d)

  • List all sessions:

    tmux ls
  • Reattach to a session:

    tmux attach -t <session-name>

Working with Windows

  • Create a new window:
    Ctrl + b then c

  • Switch to the next window:
    Ctrl + b then n

  • Switch to the previous window:
    Ctrl + b then p

  • Rename the current window:
    Ctrl + b then ,

  • Close the current window:
    Ctrl + b then &

  • List all windows:
    Ctrl + b then w


Working with Panes

  • Split pane horizontally:
    Ctrl + b then "

  • Split pane vertically:
    Ctrl + b then %

  • Switch to the next pane:
    Ctrl + b then o

  • Close the current pane:
    Ctrl + b then x

  • Resize pane:
    Ctrl + b then : then resize-pane -[L|R|U|D] <size>

  • Zoom into a pane (maximize):
    Ctrl + b then z
    (Press again to unzoom)


Session Management

  • Kill a session:

    tmux kill-session -t <session-name>
  • Kill all sessions:

    tmux kill-server
  • Rename a session:
    Ctrl + b then $


Copy Mode (for scrolling and copying)

  • Enter copy mode:
    Ctrl + b then [

  • Scroll up/down:
    Use Up/Down arrows or Page Up/Page Down

  • Start selecting text:
    Press Spacebar

  • Copy selected text:
    Press Enter

  • Paste copied text:
    Ctrl + b then ]


Customization

  • Edit the tmux configuration file (~/.tmux.conf):

    nano ~/.tmux.conf
  • Reload the configuration:
    Ctrl + b then : then source-file ~/.tmux.conf


More Tips

  1. Enable mouse mode: Add this to your ~/.tmux.conf to enable mouse support:
    set -g mouse on
  2. Use tmux with SSH: Keep your sessions alive even if your SSH connection drops.