logo

Terminal Multiplexer (tmux)

This module discusses some features of tmux.

Introduction

Tmux is a tool that can create sessions, windows and panes within one terminal. Windows can be thought of as tabs and panes can be thought of as running two terminals side by side. Or to use a house as the analogy, a house (session) has many windows, some fancy windows have panes inside. Within a sesion you can have many things going on but the advantage is if run on a remote machine you can disconnect the ssh connection, go away, reconnect later and resume where you left off! Great for remote work or running calculations that require a persistent shell.

Tmux example as a Python IDE Tmux emulating an IDE with nvim, pydoc and ipython in one window

tmux is newer compared to GNU screen (screen), which is an older program of similar capability. Your remote computer may use screen instead. As always man tmux or man screen for more help and options.

Once running in tmux commands are preceeded by a prefix (C-b) which is CTRL-b. Settings can be added and changed in the configuration file ~/.tmux.conf.

screen uses the prefix C-a and may have some overlapping commands. The default prefix can be changed in tmux if desired but be warned this may conflict with other programs C-a has some conflicts I believe.

Below are some basic commands to get you going. You need to type the prefix then type the command, e.g. to create a new window type C-b c

Default Prefix: C-b

Command Description
c create new window
d detach from tmux
n switch to next window
p switch to previous window
[0-9] switch to window [0-9]
% split window/pane into horizontal panes
" split window/pane into vertical panes
o move to next pane
q show pane numbers
q[0-9] go to pane number
w list windows and panes, select with ENTER
SPACE change pane layout
x kill current window
& kill current pane

When you detach from a tmux session C-b d you can reattach using the command line command tmux attach or tmux a for short. Generally by habit I type tmux a first and if no sessions exist then I type tmux.

There are many more features available such as moving panes between windows and sessions, see man tmux.

Sessions can be handled as such,

Copy/Paste

Selecting and pasting text requires the user to hold SHIFT while selecting text in the terminal on BSD/Linux. In MacOS in iTerm to my knowledge you must type,

To copy in tmux in MacOS

To paste move the cursor to where you want then type C-b ]. Or if in BSD/Linux while holding SHIFT press middle mouse button.

Mouse mode enable

One useful feature is enabling mouse so you can click between panes, and windows. This can be done as of v2.1.

$ cat ~/.tmux.conf
set -g mouse on

Any changes to ~/.tmux.conf require you to kill all tmux sessions and restart them to take effect.

With mouse mode enabled you can issue C-b and hold the left mouse button and resize borders as you drag the mouse!

© 2017–2022 David Kalliecharan