Tmux cheatsheet

Reference commands for the tmux terminal multiplexer.

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

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 and pasting text between panes

  1. Enter copy mode: prefix+[.
  2. Start selection: Space.
  3. Select the text to copy using arrow keys.
  4. Copy text: Enter.
  5. Switch to other pane.
  6. Paste text: prefix+].

Alternatively, here’s a quick method that works using the mouse.

  1. Zoom the pane using z.
  2. Copy the desired text using the mouse.
  3. Zoom back out with z.

Note that this approach generally only works well for short snippets.

References

This guide was developed using these sources: