Installing tmux

Getting tmux ready and running on your system is relatively simple if you are using a Linux distribution. For Ubuntu, this means summoning apt from your terminal and installing the package from the distribution’s official repository. For other distros, use your included package manager to handle the installation. (tmux is available on most distributions.)

Got it? Great! Now, let’s split our screen.

Creating Windows and Panes

In tmux, two terms are used to describe the main types of layout configurations we can create. “Windows” are the tmux term for tabs. Creating a new window will make a tab that you can switch over to with a simple command. “Panes,” on the other hand, are splits in the current “Window” or tab that can also be switched to using a command. Before we begin creating these, it is important to note that tmux is modal in function. What this means is that interactions with your terminal session and with tmux happen in separate “modes.” This is useful as you can use each individual terminal session you open normally without accidentally activating a tmux command. To gain access to tmux and begin issuing commands, we’ll first start our new tmux session and name it:

Feel free to change the name (“babytmux”), of course! Tmux should open immediately, and a new shell session should start up for you. But we want more than one, remember? To enter tmux’s command mode, we’ll need to use the prefix. This is usually Ctrl and b pressed simultaneously. Alone, you won’t notice anything changing by pressing the prefix, but we can type out commands by entering : immediately after. To leave command mode, either complete the command by pressing Enter or press the ESC key to exit without making changes. Tip: Get our Tmux keyboard shortcuts cheatsheet for a complete overview of basic keybindings. We’ll use a shortcut to create a horizontal split: Press Ctrl and b, then "

Cool! Now, we can navigate between the two with the following: Ctrl and b, then o.

Each session is independent of the other, so we can open separate programs in each. Let’s quarter our screen with vertical splits and try it out: Ctrl and b, then % Open whatever you want in each pane, and it will keep running while you access the others.

To make a window, use the following: Ctrl and b, then c You can switch back to a previous window or move forward one window with: Ctrl and b, then p or Ctrl and b, then n

The status bar at the bottom of the screen shows you a process that is running in each window and which window you are on (with “*”) for reference. To leave this tmux session, use this: Ctrl and b, then type :detach-client

Your session will not stop running unless your machine is rebooted or you manually cancel it. To access it again, use this: To create truly immortal tmux sessions that can come back after a reboot, we need to install a plugin or two.

Installing Plugins

Using plugins in tmux is relatively straightforward. However, there is a plugin manager we can install to make subsequent plugin installations easier.

Plugin Manager

To install Tmux Plugin Manager, we will clone its files from Github with the following code: Next, add the following code to “.tmux.conf” in your home folder:

As you can see above, we will need to add the github username and plugin name (found in a plugin’s github URL) for each plugin we want to install from now on. The plugin manager will handle the rest. Use this code to get the plugin manager working: Now, for the plugin we need to restore sessions after rebooting, keep reading.

Resurrect

Tmux Resurrect does just what its name suggests and brings your saved session back to life using a simple command. This plugin can be installed by adding the following to your .tmux.conf file:

Now, let Tmux Plugin Manager install it by using the following command in tmux: Ctrl and b, then I (This is “i” in UPPERCASE.)

Once installed, we can start a session and save it with the following: Ctrl and b, then Ctrl + s To restore our session, we can use Ctrl and b, then Ctrl + r

Using the above, you can maintain an immortal tmux session with all of your preferred tools and processes in place even after rebooting. Give it a try and explore more of tmux’s features to get the most from your terminal.