DEV Community

Cover image for Why I *love* TMUX
Antonin J. (they/them)
Antonin J. (they/them)

Posted on

Why I *love* TMUX

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.

Top comments (15)

Collapse
 
patryktech profile image
Patryk

Tmux is the best. I usually have one open terminal tab per project I am currently working on, and tmux in there with a 4 pane split... One where I run docker-compose up (without daemonizing, since I often want to kill / rebuild / restart containers e.g. when changing dependencies), one for git, one for bash inside my python / Django container (for migrations, startapp, pytest etc.), and one for my node.js container (for jest, yarn add ..., etc.)

My favourite thing is to also use a drop-down terminal (yakuake, as I use KDE, but you can also use guake for Gnome). Then I can just toggle my terminal with F12, and easily switch from the terminal to VSCode or Chrome, and vice-versa.

Collapse
 
antjanus profile image
Antonin J. (they/them)

I've seen that setup! One of my colleagues (maybe 2 actually?) sets up a grid of terminals that run everything that you might want to glance at and then edits in one big terminal.

I'm not a huge fan of drop-down terminals but I guess that's because the terminal is my entire workspace -- including editing.

Collapse
 
patryktech profile image
Patryk

I'm not a huge fan of drop-down terminals but I guess that's because the terminal is my entire workspace -- including editing.

Yeah, it would probably annoy me if I used vim for entire projects. I only use it for quickly editing a handful of files, or on remote servers.

Collapse
 
waylonwalker profile image
Waylon Walker

Tmux is so scriptable and customizable. Thats my favorite part of any terminal application really. My favorite shortcuts are my hotkeys for splitting, windowing, and navigating new windows. I closely mirrored the existing commands with alt instead of c-b.

alt+s - split
alt+v - vsplit
alt+c - create new window
alt+n - next window
alt+p - previous window

alt+[hjkl] - go to [left,lower,upper, or right] split

This makes it super quick to have vim open and gatsbt develop like you mentioned to jump between running servers, a shell, and vim.

Sadly copy and paste support on wsl is atrocious. Makes it hard to paste in something a team mate sent in chat.

Collapse
 
antjanus profile image
Antonin J. (they/them)

oooh, I like that alt thing! That didn't even occur to me, I got so used to the Ctrl+a mapping that many tutorials suggested when I started early on that I can't imagine doing things any different way.

Yeah copy/paste no matter where is a pain in the ass. I'm thinking of using the tmux-yank plugin that's supposed to handle copy/paste on all platforms including via SSH and WSL.

Collapse
 
waylonwalker profile image
Waylon Walker

Two keystrokes is ok for single commands, but multiple in a row is a pain. For instance checking on a server running in an adjacent window and getting back is a simple alt+n+n.

My first post on Dev walks through replicating my alt key setup from tmux to vscode dev.to/waylonwalker/keyboard-drive.... I honestly use vscode mostly for copy and paste. Every time I go to use tmux I end up pairing with a team mate an thier like what is this you cant even paste properly here. I have my hotkeys setup so similarly that I can switch between them comfortably.

Collapse
 
idrisrampurawala profile image
Idris Rampurawala • Edited

Tmux is an ideal solution for me on remote servers, where generally we are are dealing with multiple commands and paths to different software/tools. Also, viewing multiple logs in parallel for resolving issues.

Collapse
 
jay97 profile image
Jamal Al

Unfortunately, it does not support serial communication like screen does.

Collapse
 
antjanus profile image
Antonin J. (they/them)

ooh, I'm not super aware of that. What does that mean for usability? Or, when do you need serial communication?

Collapse
 
jay97 profile image
Jamal Al

Some devices support the ability to configure them through a serial port (its like sshing into ur router) or URAT port. Although it’s not a big issue because thankfully there are other ways to work around this, it would’ve been nice to have by default.

Collapse
 
chiptus profile image
Chaim Lev-Ari

Thanks for writing this. Very interesting, I'll have a look. Any link for a beginner tutorial?

Collapse
 
antjanus profile image
Antonin J. (they/them)

I started using Tmux almost six years ago and can't find the original article, unfortunately. And none of the current guides are to my taste.

I'd say, find a guide that helps you install it locally, and then peruse youtube for a more visual guide. Cheatsheets are also useful

I started on a series called "How I Work" where I cover how I use tmux for work. You can kind of see the tmux flow there and I also linked to a cheatsheet as well as my dotfiles there.

Collapse
 
flrichar profile image
Fred Richards

Tmux is like jazz. The music never stops playing.

Collapse
 
batorshikh profile image
Bat-Orshikh

Hello,
How can I configure copy past key bindings to my OSX system clipboard?

Collapse
 
antjanus profile image
Antonin J. (they/them)

solid question, looks like searching for it yields a few different answers. I'll be honest... I haven't set up copy to system clipboard because I rarely use it (I tend to copy/paste between panes/tabs).