Hi! Well, it’s kind of my first post here, and I mainly try to test the blog and everything. But Tmux was on my list of things to write about, and I use it every day, so why not start with it!

What I thought the Tmux was

I’ve been in the IT world for years already (for 11 years actually), and of course I’ve heard of Tmux before. But I’ve never tried it until last year.

I was sure that it’s some old tool made and used by sysadmins only when they need to run long sessions on remote servers. And it wasn’t exactly wrong. And I saw people using it exactly this way.

For example, you need to run a migration in your db after an update. It’s a long process, you don’t want this process to be interrupted, so you can’t rely only on your SSH connection, or yourself not closing the terminal windows accidentally. In this case you can just run tmux on a remote host, run the migration and do whatever you want (except for :kill-session for obvious reasons). In case of any problem you can just connect back to this host, connect to the same Tmux session (just tmux a usually) and boom, you’re back in business, migration is still running, you can look at it closely and pretend you’re working hard.

And that’s all! That’s all this piece of software does.

Or is it?

Long ricing way to Tmux

At the beginning of my career I was a windows guy. I even was an administrator for a bunch of windows servers.

Luckily I stopped being a sinner and at some point accepted Linux.

And the OS I started with was, btw, Arch Linux.

I quickly realized that the most important thing in your Linux environment is a window manager. I also realized that the i3wm is the best one.

I spent days configuring it. I wrote a lot of scripts, changed a lot of key bindings, set all the workspaces (and the icons for all of them of course).

I was really happy using it. Though I also struggled a lot…

It’s definitely a lack of skills, but it was breaking a lot. Some windows showed only a white screen (PyCharm), floating windows were always a mess, and the whole automation around the system tended to fail on every update (not exactly an i3 problem, but come on, you know what I mean). In other words, it was really hard to build a reliable system from scratch.

Then I tried all the other things like Sway, bspwm, Hyprland, you name it. But we’ll skip this part because the post is about Tmux.

At the end of this part of my life I had to move to another country, and I decided to take my wife’s MacBook Pro instead of my own laptop with Linux, because it was more reliable, and I couldn’t afford to fix yet another Arch update at that time.

And that’s how the reassessment-of-values part started.

Do I even need a system from scratch?

So I started to use a Mac. Everything was new and uncomfortable. I tried to recreate the same environment I had on Linux. It was always a mess.

I decided to give macOS a chance and use it as intended. And you know what? I got used to it.

And after I got used to it I realized that the only thing I needed i3 and tiling for specifically was my terminal.

So I spent some time learning iTerm2 bindings for tabs and panes. And that’s all. I finally was happy. Nothing breaks, everything works, and I have kinda tiling in my terminal.

After some years of working on a 10-year-old Mac I decided that I needed an upgrade (tbh it was mostly the lack of gaming options on the old Mac). I built a PC, which I might write a separate post about. And I installed on it what? Arch Linux with i3 of course (lightning strikes stupid people twice).

Soon after I realized that I’m too old for this shit. I have a lot of tasks, I have my team I need to manage, and I have my beautiful son I need to manage even more. I just don’t have time for ricing, configuring, problem solving on my working system.

And the solution was: Fedora + KDE.

Yeah, I just installed it and it was fine.

But what about the terminal? I still needed all these tabs, panes, and other stuff. I tried Kitty, Ghostty, they’re amazing, but it was always hard to switch between my Linux environment with these terminal emulators and macOS with iTerm2.

How I learned to stop worrying and love Tmux

I can’t remember exactly why Tmux came back to my mind, it was probably one of the YouTube videos I’ve seen about useful Linux tools. After watching it I found out that it has tabs windows, panes, and even sessions. That you can split panes in different ways, you can switch between windows and sessions, move everything and so on.

And I gave it a chance (finally, after 10 years).

I’ve installed it on my Mac and Fedora and stopped using any terminal emulator features, just Tmux, nothing more.

And boy oh boy, it was AMAZING.

All the key bindings are the same, the behavior is the same as well, and I don’t even need to think about which system I’m working on anymore.

So the fact is, the tool I knew about since the beginning of my career gave me everything I needed with something like 20 lines of configuration which I can’t even remember because I almost never need to change it.

My workflow

Now, how I use Tmux.

Each day I start my computer, open up the terminal emulator (at this point it doesn’t even matter which one, but I just use Konsole on Fedora), and run tmux (yes, just like that, no arguments, nothing really special).

Then I just start working. If I need to see two pieces of something together, I create panes with <prefix>+" or <prefix>+%. If I need another window (tab) I create it with <prefix>+c. And if I need to switch to something unrelated to the current task I just create a separate session for that with <prefix>+: new -s name.

That’s all. All the struggling, reading manuals, and trying yet another cool tool was replaced with one tool, 20 lines of config, and hardly 5 key bindings.

My config

My config is pretty simple, you can see it here: https://github.com/ronedier/dotfiles/blob/main/.config/tmux/tmux.conf

But I want to highlight some things.

Do not change the prefix key. Just get used to it.

I’ll definitely write another post about default key bindings in general, but for now just think about being able to use Tmux anywhere without relying on your specific setup. It’s not that hard to type ctrl+b. I recommend remapping your CapsLock key to CTRL; it will give you much more than changing the prefix key in Tmux.

Do not change the bind-key for window splitting.

I’ve seen a lot of configs and recommendations which tell you to do that, mostly because people can’t memorize the standard binds. Well, I’ll tell you how to memorize it.

Look where the % symbol is on your keyboard. Try to draw the line from this key. The only meaningful way to do it is vertically. This way you split your keyboard with a vertical line in half. The same way as <prefix>+% splits your window with a vertical line in half.

Now look where the " symbol is on your keyboard. Try to draw the line from this key again. The only meaningful way to do it is horizontally. This way you split your keyboard with a horizontal line in half. The same way as <prefix>+" splits your window with a horizontal line in half.

What you can change in split-window behavior is this

plain
## Split window and cd to the current path
bind-key %   split-window -h -c '#{pane_current_path}'
bind-key '"' split-window -v -c '#{pane_current_path}'
## Create window and cd to the current path
bind-key c   new-window -c '#{pane_current_path}'

Because changing directory back to your current project path every time you need an additional pane or window is pretty annoying.

The main key binding you need to remember is <prefix>+?. It’s easy to guess that it opens a help window with all the other key bindings. You can just search it. You don’t even need a cheat sheet. (But you can use this if you want to: https://tmuxcheatsheet.com/ ).

You don’t need to remember each key binding or even use all of them.

I remember only maybe 6 which I use regularly. For a lot of things you can just run <prefix>+: which will open a Tmux command line and type the function you want to run. Set a key binding for it or memorize the existing key binding only if you use this function regularly.

You’ll definitely want this to clear both screen and scrollback history:

plain
## clear scrollback history (like cmd+k in iTerm)
bind-key -n C-l send-keys C-l \; send-keys -R \; clear-history

You want this to make your window indexes start from 1 instead of 0

plain
# Start windows and panes at 1, not 0
set -g base-index 1
setw -g pane-base-index 1
set -g renumber-windows on

I can’t imagine why someone may want to start it from 0 since it’s a pretty uncomfortable key to press.

You want this as well:

plain
set-option -g detach-on-destroy off

To make Tmux switch to another session instead of a full detach when you close the current one (or close the last window in the current session).

La Finale

That’s all you need to know.

Now you can use Tmux on any OS, with any terminal emulator, on your PC, laptop, or even on a remote server (just press your prefix twice if you run Tmux on the server while running Tmux on your machine).

As you can see, I spent more time explaining my way to Tmux than Tmux itself, because I think it’s more important to understand why you use a tool, instead of explaining how it works, especially if this tool is so simple.