Awesome FOSS Logo
Discover awesome open source software
Launched 🚀🧑‍🚀

From Zellij to Tmux Back to Zellij

Categories
tmux logo / Zellij Logo

tl;dr - I switched from tmux to zellij, but returned to tmux primarily because of missing no-mouse on-screen text selection, and easy screen rotation

To set the record straight – both tools are great.

Zellij is awesome. I made up my mind to try it for many reasons:

  • Zellij looks great
  • Zellij has a great set of out-of-the-box features
  • Zellij is extendable
  • Zellij is written in Rust

Obviously, tmux is also great – I consider it the defacto choice these days (though there are screen diehards I’m sure, and people who use other higher lever or even lower level tools).

If you’ve been living in a world where you opened tabs or multiple windows in iTerm or Terminal (or whatever terminal app you’re using) and have been tabbing between or even worse clicking between them, invest time in learning to use a terminal multiplexer.

Life with a terminal multiplexer is better than life without. That said, if these are both perfect, why would I ever need to switch between them?

Why switch from tmux?

There is one distinct reason I felt I needed to switch from tmux: Emojis. Yes, Emojis.

My tmux setup’s handling of UTF-8 somehow doesn’t sit work well. Glpyhs are rendered, but then break upon movement or randomly. I thought this was an Emacs problem, but it actually doesn’t happen in Zellij, and as far as tmux config goes I’ve enabled UTF8 support everywhere I can find, but displaying emojis in markdown inside emacs on top of tmux continues to mess up my screen

The why isn’t quite as important as the why in the other direction probably, but basically that’s it.

So I downloaded zellij and off I went.

Friction encountered while switching to Zellij

So what was involved in my switch to Zellij? It wasn’t all sunshine and rainbows.

Updating Keybindings

Zellij keybindings definitely work for a certain set of people, but they don’t really work for me – the tmux muscle memory is obviously baked in for me (and a modified setup at that!), so I didn’t quite jive wiht Zelij’s default setup.

I personally ilke prefix-driven bindings (As a happy emacs user) and tmux hits this perfectly, though it’s awkward at first (and I have some configuration set up like many users do). It’s just so much less likely to have collisions with the prefix/chord setup.

Check out the bottom of this post for the full listing of code (or go directly to the Github repo).

Border shows up when copying text

Zellij has a border which is nice when looking at it, but you have to disable the border first, to reasonably copy any code out (or mess with the copied code)

I’m not the only one who noticed this – here’s a Reddit thread where people lament it a bit.

Technically disabling the border is only a shortcut away, but I think tmux has the right default here, where there are borders only at the top and easy rotation (which I’ll talk about later) that makes it easy.

Difficulty/impossibility of selecting with keyboard

One of tmux’s absolute killer features for me is the relative ease with which you can select text on screen. This is killer for staying in flow/on the keyboard, but when you need to grab some text that was printed to the console.

Here’s A Reddit thread where people realize it’s kind of missing.

I use this feature all the time – it’s great for pasting errors/output into issues/code/READMEs, etc.

PROTIP: Do not paste pictures into issues or pull requests as a professional developer when you could have copied text.

The exception to this is showing before/after (ex. for actual terminal UX).

Easy rotate

tmux lets you rotate the tabs you have open in a few predictable ways by using your configured prefix combination (for me Ctrl + b). Pressing the combination repeatedly cycles you through pre-configured layouts depending on how many panes you have open.

This is icnredibly useful when you’re vertically split, but have long log lines coming in (some of which you might want to copy!) – you can quickly cycle to another layout of the panes, copy (possibly without the keyboard!), then cycle back to a layout that makes more sense.

Plugins (Zellij wins here, but tmux is “good enough”)

Zellij has great session management built in (unfortunately, not quite easy to get rid of, if it’s in your way), and a great plugin system! Zellij has great forward-posture, adopting things like WebAssembly and WASI and using them appropriately.

tmux’s plugin system is inferior in some ways (and definitely has less new-shiny), but it’s good enough. tmux-ressurect is crucial for day to day work and there are a ton of other plugins that are massive improvements like it. The whole tmux-plugins org is great.

Sometimes, Zellij slowed down/flickered

Every once in a while I would see Zellij slow down and flicker intensely, seems like it’s resizing itself continuously but then figured it out.

Don’t know much more about why this was happening, it was pretty intermittent and didn’t happen often enough for me to care.

Zellij had the same display problems, just less often

Turns out, sometimes when working on a file, the output of the file would exhibit the same exact behavior as on tmux!

This worries me that it was an emacs problem from the beginning, but finding that it’s somewhat inconsistent is very annoying and invalidates the reason I switched in the first place (though of course, Zellij does this MUCH less frequently!).

The vast majority of regular files with emojis in them were fine though.

So, you filed tickets, right?

Yeah, sorry – I didn’t. I didn’t take time to contribute and file issues or write fixes for these things as I encountered them, since I’m more than happy to just go back to using tmux.

That said, I do have something to share, which is the Tmux-like setup I put together for Zellij:

The code below is the configuration file I used to make Zellij feel more like Tmux:

Code for my tmux shim for Zellij

📜️ tmux-zellij-bindings-shim (click to expand)
// If you'd like to override the default keybindings completely, be sure to change "keybinds" to "keybinds clear-defaults=true"
keybinds clear-defaults=true {
    tmux {
        bind "[" { SwitchToMode "Scroll"; }

        // Leave tmux mode
        bind "Ctrl b" { Write 2; SwitchToMode "Normal"; }

        bind "z" { ToggleFocusFullscreen; SwitchToMode "Normal"; }

        // Tab creation
        bind "c" { NewTab; SwitchToMode "Normal"; }
        bind "t" { NewTab; SwitchToMode "Normal"; }

        // Session manager
        bind "s" "$" ":" {
            LaunchOrFocusPlugin "session-manager" {
                floating true
                move_to_focused_tab true
            };
            SwitchToMode "Normal"
        }

        // Splitting panes
        // bind "\"" { NewPane "Down"; SwitchToMode "Normal"; }
        // bind "%" { NewPane "Right"; SwitchToMode "Normal"; }
        bind "|" { NewPane "Right"; SwitchToMode "Normal"; }
        bind "-" { NewPane "Down"; SwitchToMode "Normal"; }

        // Moving between tabs
        bind "p" { GoToPreviousTab; SwitchToMode "Normal"; }
        bind "n" { GoToNextTab; SwitchToMode "Normal"; }
        // Renaming tabs
        bind "," { SwitchToMode "RenameTab"; TabNameInput 0; }

        // Moving between panes
        bind "Left" { MoveFocus "Left"; SwitchToMode "Normal"; }
        bind "Right" { MoveFocus "Right"; SwitchToMode "Normal"; }
        bind "Down" { MoveFocus "Down"; SwitchToMode "Normal"; }
        bind "Up" { MoveFocus "Up"; SwitchToMode "Normal"; }
        bind "h" { MoveFocus "Left"; SwitchToMode "Normal"; }
        bind "l" { MoveFocus "Right"; SwitchToMode "Normal"; }
        bind "j" { MoveFocus "Down"; SwitchToMode "Normal"; }
        bind "k" { MoveFocus "Up"; SwitchToMode "Normal"; }
        // Renaming panes
        bind "." { SwitchToMode "RenamePane"; PaneNameInput 0; }
        // Resizing panes
        bind "H" { Resize "Increase Left"; }
        bind "L" { Resize "Increase Right"; }
        bind "K" { Resize "Increase Up"; }
        bind "J" { Resize "Increase Down"; }

        // bind "o" { FocusNextPane; }

        bind "d" { Detach; }

        bind "Space" { NextSwapLayout; }

        bind "x" { CloseFocus; SwitchToMode "Normal"; }
    }
    scroll {
        //bind "e" { EditScrollback; SwitchToMode "Normal"; }
        //bind "s" { SwitchToMode "EnterSearch"; SearchInput 0; }
        //bind "Ctrl c" { ScrollToBottom; SwitchToMode "Normal"; }
        bind "Ctrl r" { SwitchToMode "EnterSearch"; SearchInput 0; }

        // Navigation
        bind "j" "Down" { ScrollDown; }
        bind "PageDown" "J" { PageScrollDown; }
        bind "k" "Up" { ScrollUp; }
        bind "PageUp" "K" { PageScrollUp; }
        bind "d" { HalfPageScrollDown; }
        bind "u" { HalfPageScrollUp; }

        bind "Esc" { SwitchToMode "Normal"; }
        //bind "Ctrl s" { SwitchToMode "Normal"; }

        // uncomment this and adjust key if using copy_on_select=false
        // bind "Alt c" { Copy; }
    }
    entersearch {
        bind "Esc" { ScrollToBottom; SwitchToMode "Scroll"; }
        bind "Enter" { SwitchToMode "Search"; }
    }
    search {
        //bind "Ctrl s" { SwitchToMode "Normal"; }
        //bind "Ctrl c" { ScrollToBottom; SwitchToMode "Normal"; }
        bind "Esc" { ScrollToBottom; SwitchToMode "Scroll"; }

        bind "j" "Down" { ScrollDown; }
        bind "k" "Up" { ScrollUp; }
        bind "Ctrl f" "PageDown" "Right" "l" { PageScrollDown; }
        bind "Ctrl b" "PageUp" "Left" "h" { PageScrollUp; }
        bind "d" { HalfPageScrollDown; }
        bind "u" { HalfPageScrollUp; }

        bind "n" { Search "down"; }
        bind "p" { Search "up"; }

        bind "c" { SearchToggleOption "CaseSensitivity"; }
        bind "w" { SearchToggleOption "Wrap"; }
        bind "o" { SearchToggleOption "WholeWord"; }
    }
    session {
        bind "Ctrl o" { SwitchToMode "Normal"; }
    }
    renametab {
        bind "Ctrl b" { SwitchToMode "Normal"; }
        bind "Enter" { SwitchToMode "Normal"; }
        bind "Esc" { UndoRenameTab; SwitchToMode "Normal"; }
    }
    renamepane {
        bind "Enter" { SwitchToMode "Normal"; }
        bind "Ctrl c" { SwitchToMode "Normal"; }
        bind "Esc" { UndoRenamePane; SwitchToMode "Pane"; }
    }
    shared_except "tmux" "locked" {
        // Enter tmux mode
        bind "Ctrl b" { SwitchToMode "Tmux"; }
    }
}

plugins {
    tab-bar location="zellij:tab-bar"

    // note(2024/06/25): Don't need status bar with tmux bindings
    status-bar location="zellij:status-bar"

    strider location="zellij:strider"
    compact-bar location="zellij:compact-bar"
    session-manager location="zellij:session-manager"
    welcome-screen location="zellij:session-manager" {
        welcome_screen true
    }
    filepicker location="zellij:strider" {
        cwd "/"
    }
}

// Choose what to do when zellij receives SIGTERM, SIGINT, SIGQUIT or SIGHUP
// eg. when terminal window with an active zellij session is closed
// Options:
//   - detach (Default)
//   - quit
//
// on_force_close "quit"

//  Send a request for a simplified ui (without arrow fonts) to plugins
//  Options:
//    - true
//    - false (Default)
//
// simplified_ui true

// Choose the path to the default shell that zellij will use for opening new panes
// Default: $SHELL
//
// default_shell "fish"

// Choose the path to override cwd that zellij will use for opening new panes
//
// default_cwd ""

// Toggle between having pane frames around the panes
// Options:
//   - true (default)
//   - false
//
// pane_frames true

// Toggle between having Zellij lay out panes according to a predefined set of layouts whenever possible
// Options:
//   - true (default)
//   - false
//
// auto_layout true

// Whether sessions should be serialized to the cache folder (including their tabs/panes, cwds and running commands) so that they can later be resurrected
// Options:
//   - true (default)
//   - false
//
// session_serialization false

// Whether pane viewports are serialized along with the session, default is false
// Options:
//   - true
//   - false (default)
// serialize_pane_viewport true

// Scrollback lines to serialize along with the pane viewport when serializing sessions, 0
// defaults to the scrollback size. If this number is higher than the scrollback size, it will
// also default to the scrollback size. This does nothing if `serialize_pane_viewport` is not true.
//
// scrollback_lines_to_serialize 10000

// Define color themes for Zellij
// For more examples, see: https://github.com/zellij-org/zellij/tree/main/example/themes
// Once these themes are defined, one of them should to be selected in the "theme" section of this file
//
// themes {
//     dracula {
//         fg 248 248 242
//         bg 40 42 54
//         red 255 85 85
//         green 80 250 123
//         yellow 241 250 140
//         blue 98 114 164
//         magenta 255 121 198
//         orange 255 184 108
//         cyan 139 233 253
//         black 0 0 0
//         white 255 255 255
//     }
// }

// Choose the theme that is specified in the themes section.
// Default: default
//
// theme "default"

// The name of the default layout to load on startup
// Default: "default"
//
default_layout "disable-status-bar"

// Choose the mode that zellij uses when starting up.
// Default: normal
//
// default_mode "locked"

// Toggle enabling the mouse mode.
// On certain configurations, or terminals this could
// potentially interfere with copying text.
// Options:
//   - true (default)
//   - false
//
mouse_mode false

// Configure the scroll back buffer size
// This is the number of lines zellij stores for each pane in the scroll back
// buffer. Excess number of lines are discarded in a FIFO fashion.
// Valid values: positive integers
// Default value: 10000
//
// scroll_buffer_size 10000

// Provide a command to execute when copying text. The text will be piped to
// the stdin of the program to perform the copy. This can be used with
// terminal emulators which do not support the OSC 52 ANSI control sequence
// that will be used by default if this option is not set.
// Examples:
//
// copy_command "xclip -selection clipboard" // x11
// copy_command "wl-copy"                    // wayland
// copy_command "pbcopy"                     // osx

// Choose the destination for copied text
// Allows using the primary selection buffer (on x11/wayland) instead of the system clipboard.
// Does not apply when using copy_command.
// Options:
//   - system (default)
//   - primary
//
// copy_clipboard "primary"

// Enable or disable automatic copy (and clear) of selection when releasing mouse
// Default: true
//
// copy_on_select false

// Path to the default editor to use to edit pane scrollbuffer
// Default: $EDITOR or $VISUAL
//
// scrollback_editor "/usr/bin/vim"

// When attaching to an existing session with other users,
// should the session be mirrored (true)
// or should each user have their own cursor (false)
// Default: false
//
// mirror_session true

// The folder in which Zellij will look for layouts
//
// layout_dir "/path/to/my/layout_dir"

// The folder in which Zellij will look for themes
//
// theme_dir "/path/to/my/theme_dir"

// Enable or disable the rendering of styled and colored underlines (undercurl).
// May need to be disabled for certain unsupported terminals
// Default: true
//
// styled_underlines false

// Enable or disable writing of session metadata to disk (if disabled, other sessions might not know
// metadata info on this session)
// Default: false
//
// disable_session_metadata true

If you want to contribute/fix/fork the code above, do so from Github (though I won’t be maintaining it actively).