Tmux - the essentials
Tmux is a great tool for managing multiple terminal sessions and layouts. You can disconnect from a tmux session and then reconnect to it later and carry on where you left off. There is a vast amount you can configure with tmux, and many commands that can be used, and at first it can be intimidating to learn and some may fear a steep learning curve. But knowing only a handful of essential commands is enough to be productive day-to-day. I’ve been using tmux for the past two years or so and haven’t really ventured beyond these, and still, have found plenty of value out of it.
If you’ve never run tmux before and have no open sessions, just type:
This will open a new window with a single pane filling the entire screen.
One of the features of tmux is the ability to detach from a running tmux session and then be able to reconnect to it at a later time with everything being as you’d left it.
To detach from the new session you’ve just created type
b and then
d. You will now have been returned to your original command prompt.
You can see the tmux session that you were just connected to by running:
To reattach to it, type:
Tmux prefix command
Let’s talk about the tmux prefix command;
b. All commands you run within a tmux session are initiated with this. You press this combination first, and then after, the command you want to run. From here on, we’ll reference the prefix with
prefix rather than the full
Windows and panes
When within tmux there are two basic concepts that you need to know about if you’re going to use it productively; windows and panes. You can think of windows as tabs within a tmux session. They are listed along the bottom of the tmux window. Each window can have multiple panes, which are different terminal prompts split across the window in various layouts.
Each window is prefixed with a number to represent it. Type
b and then
c to create a new window. You’ll see it appear in the window list and it has been selected. You now have two windows, one represented by
0 and the other by
You can switch between windows by typing
0 to jump to the first window. Just use the number index to choose which window you want to switch to.
When you start creating lots of windows, it becomes hard to remember what is within each. By default each window will be named with the default shell it is running. To rename, type
, and then enter a new name, then hit enter. You’ll see the name reflected in the window list displayed along the bottom of the screen.
Within window 0, let’s create some panes. Type
% to split the current window into two vertical panes. You’ll notice the right-hand pane currently has the terminal focus.
q and the number for each pane will briefly appear on the screen. This is how you will navigate between panes. The numbers will disappear after a second or so. Just push the combination again
q and then type
0 immediately to switch focus back to the leftmost pane.
Now go back to the rightmost pane with
q and then
1. We can split this pane in two horizontally by pressing
q again and you can now see we have three panes indexed with 0—2.
Sometimes it’s very helpful to zoom in on a single pane. A good example is when you want to copy and paste the contents of a pane that go over more than one line. To zoom press
z. You’ll notice the pane expands to fill the entire window. Also a
Z will appear in the window list along the bottom. To unzoom, just press
Summary of commands
tmuxcreate a new tmux session
tmux lslist any existing tmux sessions
tmux areattach to the last open tmux session
bthe default tmux command prefix
ddetach from current tmux session
ccreate a new window
9to switch to the numbered window
,rename the existing window
%split the current pane into two vertical panes, left and right
"split the current pane into two horizontal panes, top and bottom
qview numbered panes for current window
9switch to pane immediately after displaying pane numbers
zto zoom and unzoom