How to Use `tmux` for Terminal Multiplexing on Arch Linux

How to Use tmux for Terminal Multiplexing on Arch Linux

Terminal multiplexers are essential tools for anyone working extensively in the command-line environment. One of the most powerful and popular multiplexers is tmux, a terminal multiplexer that lets you switch between multiple programs in one terminal, detach and reattach sessions, split terminal windows into panes, and more. On Arch Linux, tmux integrates seamlessly and can drastically boost your productivity, whether you’re a system administrator, developer, or power user.

In this article, we’ll explore the features of tmux, how to install it on Arch Linux, and how to get started using it effectively.


What is tmux?

tmux (short for terminal multiplexer) allows users to run multiple terminal sessions inside a single terminal window or remote SSH session. These sessions are persistent, meaning they can be detached and reattached even after logging out. With tmux, you can:

  • Split terminal windows into multiple panes.
  • Manage multiple terminal sessions.
  • Detach and reattach to sessions at will.
  • Automate complex workflows.
  • Keep long-running tasks running in the background.

Think of tmux as a window manager for your terminal.


Installing tmux on Arch Linux

Step 1: Update your system

Before installing new packages, it’s a good idea to update your system:

sudo pacman -Syu

Step 2: Install tmux

You can install tmux from the official Arch repositories:

sudo pacman -S tmux

After installation, verify it:

tmux -V

You should see output like tmux 3.4 or a similar version depending on what’s current.


Starting Your First tmux Session

To start using tmux, just type:

tmux

This opens a new tmux session. You’ll see something that looks just like your usual terminal, but now you’re inside a tmux session.

At the bottom, you might see a green status bar showing the session name and window number.


Basic tmux Commands

All tmux commands are triggered by a prefix. The default prefix is:

Ctrl + b

This means you press Ctrl + b, release them, and then press the next key to send a command to tmux.

Essential commands

Here are some commonly used keybindings after pressing Ctrl + b:

Key ComboAction
Ctrl + b cCreate a new window
Ctrl + b nNext window
Ctrl + b pPrevious window
Ctrl + b &Kill the current window
Ctrl + b %Split window vertically (pane)
Ctrl + b "Split window horizontally (pane)
Ctrl + b oSwitch to the next pane
Ctrl + b xKill the current pane
Ctrl + b dDetach session
tmux attachReattach to a detached session
tmux lsList all active sessions

Let’s go through some of these in more detail.


Working with Windows

In tmux, each “window” is like a separate terminal session. You can:

  • Create multiple windows (Ctrl + b, then c).
  • Switch between them (Ctrl + b followed by n or p).
  • Rename a window:
    Press Ctrl + b then , and type the new name.
  • Kill a window:
    Press Ctrl + b then &.

This allows you to group related tasks in different windows (e.g., one for editing code, one for running a server, one for logs).


Working with Panes

Panes allow you to split a window into multiple regions.

Create Panes

  • Vertical split (side by side):
    Ctrl + b then %

  • Horizontal split (top and bottom):
    Ctrl + b then "

  • Press Ctrl + b then use arrow keys (← ↑ ↓ →)

Resize Panes

Hold Ctrl + b, then press and hold one of the arrow keys with Ctrl:

Ctrl + b, then hold Ctrl + Left/Right/Up/Down

Alternatively, enter resize mode:

Ctrl + b :resize-pane -L 10

(L = left, R = right, U = up, D = down, followed by number of cells)

Kill a pane

Press Ctrl + b then x.


Detaching and Reattaching Sessions

This is one of tmux’s most powerful features.

  • Detach: Press Ctrl + b then d. You’ll return to your regular terminal with a message like [detached].
  • List sessions: Use tmux ls
  • Reattach: Use tmux attach-session -t <session-name>

Or just:

tmux a

To reattach the most recent session.

Named Sessions

Name a session when creating it:

tmux new -s dev

Later, you can reattach with:

tmux attach -t dev

You can also kill it:

tmux kill-session -t dev

Customizing tmux

To customize your experience, create a .tmux.conf file in your home directory:

nano ~/.tmux.conf

Here are some popular customizations:

# Set prefix to Ctrl + a (like GNU Screen)
unbind C-b
set -g prefix C-a
bind C-a send-prefix

# Enable mouse support
set -g mouse on

# Set 256-color mode
set -g default-terminal "screen-256color"

# Enable vi-style key bindings
setw -g mode-keys vi

After editing, reload the config without restarting tmux:

tmux source-file ~/.tmux.conf

Scripting and Automation

You can create and control sessions programmatically. Here’s an example to create a session with multiple panes:

tmux new-session -d -s mysession
tmux send-keys -t mysession 'htop' C-m
tmux split-window -h -t mysession
tmux send-keys -t mysession:0.1 'tail -f /var/log/syslog' C-m
tmux attach -t mysession

This starts htop on the left pane and a log monitor on the right.


Plugins and Enhancements

To supercharge your tmux, you can use the Tmux Plugin Manager (TPM).

Install TPM

git clone https://github.com/tmux-plugins/tpm ~/.tmux/plugins/tpm

Add this to the bottom of your .tmux.conf:

# List of plugins
set -g @plugin 'tmux-plugins/tpm'
set -g @plugin 'tmux-plugins/tmux-sensible'

# Initialize TPM
run '~/.tmux/plugins/tpm/tpm'

Reload the config, then press Ctrl + b and I to install plugins.

Popular plugins:

  • tmux-resurrect: Save and restore sessions.
  • tmux-continuum: Auto-save tmux sessions.
  • tmux-battery: Show battery status in the status bar.

Troubleshooting Tips

  • Text display issues: Ensure your terminal supports 256 colors and is set correctly (TERM=screen-256color).
  • Mouse not working: Add set -g mouse on in .tmux.conf.
  • Slow key response: Adjust key repeat rates in your terminal or OS settings.

Conclusion

tmux is a powerful and flexible tool that can greatly improve your productivity on Arch Linux. Once you get used to the keybindings and workflows, it becomes an indispensable part of your command-line toolkit. Whether you’re managing servers, developing software, or simply multitasking in the terminal, tmux enables persistent, organized, and efficient workflows.

Take the time to customize your setup and explore plugins — and don’t forget to save your .tmux.conf in your dotfiles repo for easy setup across systems.


Further Reading