5 Simple Tricks I Use to Make Good Use of Tmux in Linux

A picture of a person frustrated in front of a computer.

Tmux can be a confusing program if you’re new to Linux and the terminal. With its obscure commands and keybinds, it’s no surprise that some might find it unintuitive and frustrating to use. In this article, I will go through some simple tricks I did to learn and fully utilize Tmux in my daily Linux workflow.

1. Using the Prebuilt Tmux Layouts

I’m a big fan of terminal-based programs. From my podcast player to my RSS feed reader, I always try to incorporate some part of my workflow to the console. As a result, I often have to juggle between multiple terminal windows in a single session.

A terminal showing three vertical panes in Tmux.

One of the first tricks I learned while using Tmux in Linux is taking advantage of its pane layouts. These are prebuilt arrangements that evenly space out your active terminals on single Tmux window. For instance, pressing Ctrl + B, then Alt + 2 will evenly space out your panes horizontally.

A terminal showing a horizontally spaced panes in Tmux.

By default, Tmux comes with five pre-built layouts. You can access them by pressing Ctrl + B, followed by Alt then any number from 1 to 5. You can also press Ctrl + B, then Space to cycle through them one by one. Personally, I use the Alt + 4 layout since it mimics how dwm handles windows.

A terminal showing a dwm-like layout in Tmux.

On a side note: looking for some programs to pair up with Tmux? Check out our picks for the best terminal-based tools on Linux today.

2. Controlling Nested Tmux Sessions

If you’re like me, you’ve most likely installed and used Tmux on every system you own. You’ve also probably been in a situation where you ran tmux attach on a remote Linux system while still inside Tmux on your local PC.

A terminal showing a nested Tmux session.

When this happens, the remote Tmux session nests itself inside the local instance. This makes it inaccessible from standard Tmux keybinds, which can disorient new users. Luckily, Tmux treats its leader key as a passthrough when it detects it’s nesting another multiplexer session.

Note: Tmux doesn’t allow nesting when running locally. However, you can test this on your PC by typing unset $TMUX, and then running Tmux again.

To control the nested session, press Ctrl + B, followed by the keybind you want to run. For instance, pressing Ctrl + B, Ctrl + B, then W will open the pane switcher for the nested window.

A terminal showing the nested Tmux being controlled by the user.

You can also control the Tmux session on top of the nested instance by running the regular Tmux keybinds. For me, I use this simple Tmux trick heavily when I’m managing multiple virtual servers and Docker containers for my Linux-based home lab.

3. Copying and Pasting Text from Buffers

One of the trickier parts of Tmux, especially for beginners, is understanding how multi-pane text selection and clipboards work. When I was starting out, I found Tmux difficult to copy text from since it would often wrap around the entire window and cutting across different panes.

A terminal showing the wrapping effect that happens when you select text normally in Tmux.

The easiest way to solve this issue is by using Tmux’s copy mode, which allows you to select text within a Tmux pane. To do this, press Ctrl + B, then [ (Left Square Bracket) on the pane that you want to copy from.

Press Ctrl + Space to enable Selection Mode, then use the Arrow Keys to select your text.

A terminal showing the properly selected text using Tmux's copy mode.

Once you have selected your text, press Ctrl + W to add it to your clipboard. Doing this will also automatically bring you back to Tmux’s normal mode.

To paste text from your Tmux’s clipboard, press Ctrl + B, then ] (Right Square Bracket). You can also keep track of the content of your Tmux buffer by running tmux show-buffer.

A terminal showing the pasted buffer on a different terminal pane in Tmux.

Tip: If you’re using X11 in Linux, you can pipe the show-buffer subcommand to xclip to move your Tmux clipboard to your desktop: tmux show-buffer | xclip -sel clip.

4. Adjusting Windows and Using Marked Panes

While Tmux provides a decent collection of prebuilt layouts, there can be instances where you want to slightly tweak how each individual pane looks. In my case, I usually readjust my Tmux layout when I run either Vim or htop remotely.

A terminal showing the default pane sizes in an Alt + 4 Tmux layout.

To adjust the size of a Tmux pane, press Ctrl + B, then Alt followed by the Arrow Key direction that you want to expand to. For example, pressing Ctrl + B, then Alt + Up Arrow will expand the pane upwards.

A terminal showing the adjust pane sizes in Tmux.

You can also use Tmux-specific commands to create precise adjustments to your terminal panes. For that, press Ctrl + B, then : (Colon) to bring up the command buffer.

Once there, type “resize-pane” followed by the direction and the amount of pixels you want to adjust to. For instance, typing resize-pane -R 5 will expand the pane to the right by five pixels.

A terminal highlighting the resize-pane command in the Tmux buffer.

Lastly, you can also mark your Tmux panes for later use. As an avid CLI user, this helps me keep track of where my important terminal windows are. To mark a pane, press Ctrl + B, then M. This will add border around your pane, making it easier to track during a session.

A terminal showing the marked pane inside Tmux.

Good to know: take a deep overview of how Tmux functions under the hood by checking out our extensive cheatsheet for Tmux.

5. Extend My Tmux Functions with Plugins

On top of its built-in features, Tmux is also a highly extensible terminal multiplexer. With the help of a plugin manager, it’s possible to add just about any feature you want to the program. This little trick alone makes Tmux incredibly attractive to customization junkies like me.

A screenshot showing the Github page for the Tmux Plugin Manager.

To start extending your Tmux install, first use Git to clone the Tmux Plugin Manager repository to your system:

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

Open the “~/.tmux.conf” file using your favorite text editor and paste the following inside it:

set -g @plugin 'tmux-plugins/tpm'
set -g @plugin 'tmux-plugins/tmux-sensible'

run '~/.tmux/plugins/tpm/tpm'

Note: if the “.tmux.conf” file doesn’t exist on your home directory you can create it by running touch ~/.tmux.conf.

Reload your Tmux session either by exiting it or running tmux source ~/.tmux.conf.

At this point you can now add Tmux plugins by adding its entry on the “.tmux.conf” file and pressing Ctrl + B, then Shift + I.

A terminal showing TPM installing the plugins on my Tmux instance.

These simple tricks are just the tip of the iceberg when it comes to terminal multiplexers and Tmux. Take a deep dive into how this tool can further optimize your workflow by learning how to restore previous Tmux sessions through a plugin today.

Image credit: Grok via x.ai. All alterations and screenshots by Ramces Red.

Subscribe to our newsletter!

Our latest tutorials delivered straight to your inbox

Ramces Red Avatar