Zellij vs Tmux

Maybe you've viewed our Tmux for Newbs course and you've drank the kool-aid. You're loving it, but you keep hearing about Zellij. Or maybe you've just been living that VS Code life or just running Neovim without any "terminal multiplexer".

We're going to break down what terminal multiplexers are and then review how Zellij works and how it stacks up to Tmux.

Buckle up because we're going to learn all the important things about Zellij — including how you pronounce it.

Let's get After It!

What is a terminal multiplexer?

To understand the benefit of it, we need to understand where we're starting from. To do that, we need to understand what happens we login to the terminal.

Let's say for example we use iTerm2 and open it. Behind the scenes, a pseudo login session is created. Every time I open a new window or pane, the same thing happens.

So basically, a diagram for that would look like this.

One-to-one

This works but whenever we're working on a project, we typically end up having multiple windows or panes open. For running a server, for opening Neovim or for running tests. There is no relationship between these windows or panes.

Terminal multiplexers change the game by introducing the ability to multiplex multiple virtual terminals in one pseudo login session.

We go from our stickman having a 1-to-1 between pseudo logins and windows or panes to having as many as we need.

From one to many.

This is true for Tmux and also Zellij. So what does Zellij offer over the stable, tried-and-true Tmux?

Installation

Installation is made pretty simple. You can try it without installing it if you're using bash/zsh or fish.

bash <(curl -L zellij.dev/launch)

bash/zsh

bash (curl -L zellij.dev/launch | psub)

Fish

Once you've dipped your toe in the water, you can install it with a linux download or macOS download. You can find all those here. You can even install it using homebrew if you're on Mac OS.

brew install zellij

Homebrew

If you've been following along our Linux for Newbs course, you may be living that Arch life, btw. In that case, you can use yay.

yay -S zellij

Arch Linux

Once you've got it installed, it's time to play. Let's open it up by running zellij.

It's clear right away that this isn't the same as Tmux. It might feel a bit noisy, but if you look at the bottom, you'll see a row of keybindings to navigating Zellij.

Keybindings

Let's see what the pane command does by pressing Ctrl+p.

When you select pane, the options underneath change. You can think of this almost like a dropdown menu in an application.

Pane options

Now we can see we can create a new pane, move it, close it, and even rename it. For now, let's open a new pane by pressing n.

Just like that, we have two panes sitting side by side.

Two panes

I don't need two so we'll go ahead and close that by pressing Ctrl+p to open the pane sub-menu and pressing x to close it.

💡
You'll notice that opening a 3rd pane will put it underneath the 2nd pane. Zellij manages the placement of the next pane. If you want to control it instead, you can use (Ctrl+p) + r to open a pane to the right or (Ctrl+p) + d to open a pane underneath.

Now you may be a life-long Tmux user so these keybindings may trip you up. If you want, you can use Tmux keybindings to ease your transition to Zellij.

To turn this on, you can just use the default prefix for Tmux (Ctrl+b) and then use the Tmux command you wanted. Open a new vertical pane with (Ctrl+b) + %` or horizontally with (Ctrl+b) + ".

Navigating panes or opening new windows also works the same way. This makes it easy to try Zelliji coming from Tmux without forcing you to learn new keybindings to be productive.

Configuration

Now, you might think a powerful tool like Zellij would be hard to configure, but they put a lot of thought into making it easy to make your own.

mkdir ~/.config/zellij
zellij setup --dump-config > ~/.config/zellij/config.kdl

Getting your config

If you run these commands, you'll create a directory for your configuration and populate it with your current config. Looking through, it becomes pretty clear which bindings do what. Once you've tweaked it for your setup, relaunching Zellij will use your updates.

Base Configuration

Layouts

Now if you've seen our Tmux course, you know about our ability to setup layouts for our projects. It involves using other tools to make it happen, but it's doable. With Zellij, layouts are first-class citizens.

Let's make one now.

nvim ~/.config/zellij/layout.kdl

New layout

In our example, we'll open a few panes and launch a ping command to 8.8.8.8.

// layout_file.kdl

layout {
    pane
    pane split_direction="vertical" {
        pane
        pane command="ping" {
            args "8.8.8.8"
        }
    }
}

Basic layout command

💡
Now, layouts are extremely powerful. You can imagine opening multiple windows and changing directories to different panes before executing a command. That could be launching an API server, a frontend application, or opening up Neovim for each codebase driving a single-page application.

The syntax is critical, so check the documentation for more info.

Now that we have our layout, how do we launch it?

Simple!

zellij --layout ~/.config/zellij/layout.kdl

Launching with layout

And just like that, we have a window with two panes and a ping hitting 8.8.8.8. This is just touching the tip of the iceberg. Spinning up your local environment was never easier.

Session Resurrection and Management

Just like layouts, sessions are a first-class citizen in Zellij. Want to see your recent sessions? No problem. Just run zellij list-sessions.

Look ma, sessions!

You can see the sessions that are running — even including ones you've exited.

What's more if that you can navigate sessions while in Zellij! In the the keybindings listed at the bottom of your screen, you'll see one for SESSION. Just press (Ctrl+o) to load it and you can press w to see your sessions.

With a couple of arrow presses and enter, you can jump into another running session. You can hit tab to view your sessions that you've recently closed. Selecting one will resurrect it. Of course, you can create a new session by hitting tab again.

session management

So what should I use?

At Typecraft, we're not one to say, "YOU MUST USE THIS AND NOT THAT," whether that's the tools we use, the languages we write in, or even the hardware we use.

What's most important is that you use the things that make you the most efficient. For a terminal multiplexer, that's still Tmux.

If you've followed along with our Tmux for Newbs course, you know that we've got Neovim and Tmux working together in lockstep to make us incredibly productive.

However, with all things tech, things change. You better believe we've got our eye on Zellij in anticipation of one day making the switch.