Tmux cheatsheet

Tmux is a windowing terminal emulator that allows split windows and can keep a session running in the background – useful if your working on a remote server if your connections breaks.

Useful command line options:

Start a new tmux session

tmux

List tmux sessions:

tmux ls

Attach to an existing session

tmux a

Attach to a specific session (from the list see above):

tmux a -t <session name>

The following config (usually .tmux.conf in your home directory) file changes some of the default tmux keyboard shortcuts to ones I find more intuitative (for example the tmux command prefix is now Ctrl-a (default is Ctrl-b):

  # Send prefix
  set-option -g prefix C-a
  unbind-key C-a
  bind-key C-a send-prefix

  # Use Alt-arrow keys to switch 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

  # Shift arrow to switch windows
  bind -n S-Left previous-window
  bind -n S-Right next-window

  # Mouse mode
  setw -g mouse on

  # Set easier window split keys
  bind-key v split-window -h
  bind-key h split-window -v

  # Easy config reload
  bind-key r source-file ~/.tmux.conf \; display-message "~/.tmux.conf reloaded."

Common actions

  <prefix> h - horizontal split pane
  <prefix> v - vertical split pane
  <prefix> x - prompt to close (or simply press ctrl-d)

  <alt>-<arrow key> - move  panes left, right, up, down
  <prefix> z - zoom the current session to fill the window

  <prefix> c - create new window
  <shift>-<arrow key> move window 
  <prefix> 0-9 - move to specific window
  <prefix> & - close window (or close all panes in the window using ctrl-d)
  <prefix> , - rename window

  <prefix> d - detach session
  <prefix> $ - rename session (name display is bottom corner and on `tmux ls`)
  <prefix> s - list sessions (pressing arrow key on a session will expand it)

  <prefix> : - open command mode

To close a session or window window (can get list of sessions using <prefix> s)
enter command mode (<prefix> :) and type::

  kill-session -t <session name>

or::

  "kill-window -t <window name>"

Mouse Commands

The config above enables mouse mode which means you can enter a session by
clicking on it

The cut and paste commands from selecting the text with the mouse and paste using the middle mouse button does not work in mouse mode but::

  <shift> <drag while depressing left mouse button> - will allow text to be
                                                    copied so it can be pasted
  <shift> <middle mouse button> - paste text selected above

.. hint:: to enable the wheel button to allow scrolling in `vim` when using 
          `tmux`  set the option `set mouse=a` in your `.vimrc`