Tmux cheat sheet

I’m getting started using tmux, and I’ve done my own “cheat sheet”. It’s useful to do that so you write harder in your memory and you will always¬†remember¬†the place to look at the commands, which will be this page :) !

For those who don’t know tmux, it’s a “terminal multiplexor”, like screen (which is another similar tool). It allows user to acces multiple separated terminal sessions. Because I work remotely , this tools are really useful for me and saves a me a lot of pain. The main benefits of using this kind of tools are:

  • I can have all the time my session saved, and if I loose connection or my terminal hangs I will be able to restore it.
  • I can put multiple “panes” into the view, dividing horizontally, vertically, etc.
  • I can share session with my colleagues and we can “pair program” remotely.

Basic (outside tmux)

// create session
tmux new -s {name}

// attach
tmux attach -t {name}

// kill
tmux kill-session -t {name}

// list all sessions
tmux ls

Modes (once you are inside tmux)

Ctrl+a c        # create a new window
Ctrl+a d        # detach current client
Ctrl+a x        # kill a pane or window

Ctrl+a "        # split pane horizontally
Ctrl+a %        # split pane vertically
Ctrl+a {        # move to the left pane
Ctrl+a }        # move to the right pane
Ctrl+a o        # switch to the next pane
Ctrl+a q        # show pane numbers (used to switch between panes)
Ctrl+a space    # toggle between pane layouts

Ctrl+a j (or k) # move up or down a pane
Ctrl+a h (or l) # move left or right a pane

Ctrl+a ,        # name the window (test, vim, console, log, etc.)
Ctrl+a l        # move to previously selected window
Ctrl+a n        # move to the next window
Ctrl+a p        # move to the previous window
Ctrl+a w        # list all windows
Ctrl+a {n}      # move to specified window number
Ctrl+a ?        # list all keybindings

Ctrl+a [        # enter copy mode

Finally, let me say I’ve updated my .tmux.conf. This is the content:

# act like vim
setw -g mode-keys vi
bind h select-pane -L
bind j select-pane -D
bind k select-pane -U
bind l select-pane -R
bind-key -r C-h select-window -t :-
bind-key -r C-l select-window -t :+

# act like GNU screen
unbind C-b
set -g prefix C-a

# look good
set -g default-terminal "screen-256color"