Why I *love* TMUX

Antonin J. (they/them) - Jan 28 '20 - - Dev Community

Tmux is one of those utilities like VIM. Somewhat archaic, somewhat difficult to learn, but immensely powerful. So powerful in fact, that it's hard to leave it for other setups.

In essence

tmux showing several pane splits

Tmux is a "terminal multiplexer". A multiplexer in any place is generally the idea that you have "one" of something but use it for "multiple" somethings. A terminal multiplexer lets you interact with a terminal as if there were many terminals.

A lot of terminals today already implement some of the key features of tmux from the box. This includes terminal tabs, multi-terminal positioning (such as side-by-side) view, and even saved sessions or autoloading sessions.

Tmux then is just the idea of doing it in a single terminal window, not relying on the terminal emulator itself

Tabs

screenshot of Tmux and tmux tabs

First, tabs. Tmux lets you create entire "workspaces" in a single tmux session. This means that I generally have a setup like so:

  1. VIM tab for code editing.
  2. server tab to run server (eg. gatsby develop)
  3. terminal tab to do random term tasks

On some projects, I add additional "tab" or "workspace". Each tab isn't restricted to a single terminal either. You can have as many terminals split within that tab as you want.

It's pretty common for me to split the screen in my VIM tab in two so I can use a terminal to run tests and fix the tests in VIM side-by-side.

And if you're a power user, you can even more one of those terminal splits into a completely new tab.

What else? This is fantastic for servers. You can keep one SSH connection to your server and still have access to "multiple" terminal instances. So you can run VIM, execute term commands, and so on.

Session

terminal showing a  list of Tmux sessions

So one sweet thing about Tmux is that it creates "sessions" which means that you can open several separate instances of tmux all with their own tabs and applications running.

This feature extends beyond the ability to run tmux in any terminal and get a new instance. Sessions exist beyond the terminal so if your terminal application crashes, the session is still running and you can plug back into it.

And if you lose your SSH connection to a server, you can SSH back in and reattach to a tmux session.

Guess what? You can also do this on purpose!

Session management

I see each session as a "workspace". I create a specific "work" session in tmux that has VIM, servers, and other utilities initialized and I actually rarely close it - I simply detach from the session when I'm done working. It gives me the ability to save that setup and because the tools I use are lightweight, I'm okay with the fact that the tools are always running.

And I also make a session for my writing that has VIM opened in all of the writing projects I frequent.

The session management in tmux is more of a power user utility that I started seriously using only recently but it's super useful and at this point, it's the selling feature of tmux to me.

Remote/shared sessions

tmux showing dotted area and scaling terminal output

You know how you can attach and detach from sessions, even ones on a faraway server? Imagine that you can actually attach to a single session from multiple machines. Yeah. Just think about that for second. And yes, this was available prior to VS Code introducing a similar feature.

The first cool thing about this has to do with my particular setup. I have a desktop and I have a laptop. My desktop is a Windows machine that has a superb setup but our work application doesn't work well on Windows and WSL2 still has some ways to go -- for example, it has a weird bug where it eats all of the available memory -- I had around 12gb of RAM taken up by it.

My laptop is a Linux-only machine but it doesn't deal well with constant periphery switching (basically docked vs. not docked). But I love it as a dev environment. Solution? I SSH into my machine from Windows (using their new Terminal app) and pull up Tmux.

It is fantastic. If I want to take a break from my desktop, I can just pick up my laptop, open a terminal window there, and attach to the session.

....so cool.

So why that screenshot? Tmux adheres to the lowest common denominator between several users attached to a session and then puts that output into that area, filling out the unused space with dots.

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Terabox Video Player