DEV Community

Dizzyspiral
Dizzyspiral

Posted on

The argument for terminal multiplexers

I went years without using a terminal multiplexer. I thought they were for kids who thought they were l33t hax0rz. My approach to tooling has always been minimalistic - I'm all for trying new things out, but if there's no significant improvement in my experience after a couple of days, I drop the tool.

Despite the learning curve, I saw immediate improvements in my quality of life when I started using tmux. It was definitely a "why didn't I do this sooner moment."

Embarrassing though it is in hindsight, I'll share how I used to work before learning tmux. I ssh into a dev VM for my work. I need multiple windows, so, I open up about six terminal instances and ssh each one to the dev VM. I'd use my window manager to snap the terminal windows how I liked them, and click between each one when I wanted to work in a different window. If I needed to suspend or reboot my machine, I'd close all of the ssh sessions, and then re-establish them next time, meaning I had to re-navigate to the files I was working on and redo any other working state in order to pick up my work.

a screenshot of tmux with three panes open: one running vim, one running htop, and one with a prompt

^ What tmux looks like for me - here's a post on my customizations

I cannot tell you how painful that sounds now.

Because tmux (or screen, or any other terminal multiplexer) runs on the machine you're ssh'd into, you can detach, close your ssh session, then re-connect later and pick up exactly where you left off. This nicety alone is worth it, and is why I decided to use tmux in the first place. But then you also:

  • Have the ability to switch windows using the keyboard (in a much more intelligent and seamless way than ctrl+tab).
  • You can spawn and close new terminal sessions on the machine you're ssh'd into effortlessly, making it possible to open a disposable terminal to run a single command and then close it.
  • Each new terminal pane will automatically start from a current working directory of wherever you established the tmux session, so if you cd into your project before starting tmux, every new window has a base directory there.

But wait, there's even more! Say you have multiple inter-dependent projects. You can open a session for each one, and switch between those sessions easily. It's like the equivalent of swapping workspaces on your desktop. Super handy.

Have I convinced you to try tmux? Check out what I did to make tmux work better for me, because out of the box it has a pretty terrible user experience.

Cheatsheet

Here are all the tmux commands I use to do the stuff I just talked about.

Switch sessions

<prefix> + s
arrow keys up and down to highlight session
enter to select session
Enter fullscreen mode Exit fullscreen mode

New session

tmux new -s <session name>
Enter fullscreen mode Exit fullscreen mode

New pane

Split the current pane horizontally in half:

<prefix> + "
Enter fullscreen mode Exit fullscreen mode

Split the current pane vertically in half:

<prefix> + %
Enter fullscreen mode Exit fullscreen mode

Detach from session

<prefix> + d
Enter fullscreen mode Exit fullscreen mode

Attach to session

tmux a
Enter fullscreen mode Exit fullscreen mode

Top comments (0)