Skip to content
hingen edited this page Oct 13, 2021 · 8 revisions

Description

tmux is an open-source terminal multiplexer. It allows multiple terminal sessions to be accessed simultaneously in a single window. (In other words, it allows you to edit a file using vim and run jshell for testing in the same terminal window!)
You can switch between sessions to save time while working on your code instead of having to close vim or switch around different terminals.

How to use tmux

Starting a new tmux session.

$ tmux

By default, you can enter tmux’s command mode by using a keyboard sequence called the prefix shortcut. The default is CTRL+b, but in PE node, the default is CTRL+a. (You can customise the prefix shortcut by creating/editing the ~/.tmux.conf file)

Useful commands

Hotkey Description
CTRL+b % (i.e. CTRL+b SHIFT+5) Split current pane horizontally into two panes
CTRL+b " (i.e. CTRL+b SHIFT+') Split current pane vertically into two panes
CTRL+b o / CTRL+b ; / CTRL+b UP/DOWN/LEFT/RIGHT Go to the next pane
CTRL+b+UP/DOWN/LEFT/RIGHT Resize current pane
CTRL+b [ UP/DOWN/LEFT/RIGHT (q to quit) Scrolling with keys
CTRL+b x / exit Close the current pane
CTRL+b c Create a new tab
CTRL+b <number> Switch to the tab at the specified number

Attaching to a session

Let's say you're in the middle of a lab or PA and your computer loses connection to the internet or crashes. Thankfully, if you're using tmux, you can resume from where you left off by attaching to the previous tmux session.

$ tmux ls

This will list out all the running tmux sessions. An example output is:

0: 1 windows (created Wed Oct 13 11:13:50 2021)

Take note of the session name which is the string before the : (in this case it is 0) as you will need it in the next step. By default, the string should just be a number unless you explicitly named the session.

$ tmux attatch -t 0

This will attach to the session named 0. You can replace 0 with the name of whatever session you would like to attach to.

Clone this wiki locally