Tmux quick reference

Reference commands for the tmux terminal multiplexer.

tmux is an excellent terminal multiplexer that enables multiple windows within a single terminal session.

Installation

conda method

Install using conda package manager. Recommended if you don’t have sudo access.

conda install tmux

yum method

Install using yum package manager. Recommended when working on a VM with sudo access.

sudo yum install tmux

Now that tmux is installed, here’s how to check the version.

tmux -V

Working with sessions

Note: If you run exit inside tmux, that will kill the active session, rather than detaching.

List sessions.

tmux ls

Create a new session.

tmux new -s [name of session]

Attach the most recent session.

tmux a

Attach a previous session by name.

tmux a -t [name of session]

Attach a session by number.

tmux attach-session -t 3

Kill a session by number, without having to attach.

tmux kill-session -t 0

Kill all sessions.

tmux ls | grep : | cut -d. -f1 | awk '{print substr($1, 0, length($1)-1)}' | xargs kill

Configuration

The tmux configuration can be changed with a .tmux.conf file.

Command mode

Prefix

Once you’re in tmux, you can run a command by entering a prefix key followed by a command key.

By default, tmux uses Ctrl+b as the prefix for commands. I recommend changing this to Ctrl+a in your .tmux.conf, which avoids conflicts with vim and is faster to type, with less strain.

Note that you must let go of the prefix before entering the command key.

There are many tmux commands available, but here are the only ones you need to get started:

Essentials

Panes (splits)

In situations where I’m working with multiple text documents, I find it quicker and easier to split windows inside of vim instead of with tmux. The advantage of doing this in vim is that it enables you to copy and paste text across documents in a more intuitive manner.

Windows (tabs)

Scrolling inside a pane

This is useful when needing to parse console output (e.g. interactive logs). Modified from StackExchange.

  1. [. The line numbers should appear in the top right corner.
  2. Now you can use your normal navigation keys to scroll around (eg. or PgDn).
  3. q quits scroll mode.

Copying text in a pane

  1. Zoom the pane using z.
  2. Copy the desired text. Can use the mouse, but we recommend using vim or spacemacs when working with text instead.
  3. Zoom back out with z.

References

This guide was developed using these sources: