Quick survival guide to tmux

Vilson Vieira
4 min readMay 22, 2021

Yep, this is the one. You can stop searching now. Just bookmark this page and come back here when you wanna remember some basic tmux keystroke or to setup a basic tmux config in a fresh Linux/Unix box 😉

🤔 Wait a minute, what the hell is tmux?

Tmux is a terminal multiplexer. Wait, what? Why I need that?

  • You just connected to a Linux box through SSH, but hey, I want to run more than one command at a time! One shell is just not enough! Use tmux and you can have any number of terminals you want!
  • You connected to a Linux box through SSH, but hey, I want to run this command forever! Use tmux and you can run any command you want, detach from the terminal and it will keep running. For-eh-vah!
  • You love the good and old terminal, but you want more power to switch between shells really freaking fast. Use tmux!
  • You love both the terminal and Vim. Use tmux!

🤘 Cool! How I install it?

At Ubuntu:

sudo apt install tmux

At Mac:

brew install tmux

Download this minimal config file I created at your home sweet home. It has the minimal required to improve your UX on tmux:

wget https://gist.githubusercontent.com/automata/2a3e8a276b2fd05ae13d086422dc4140/raw/b09631ed5255d32a93cd2e1f396ef52631409fcd/tmux.conf -O ~/.tmux.conf

🤓 OK it was easy… how can I use it now?

First, some basic concepts you'll become familiar with:

  • Tmux runs sessions where we can attach clients to
  • Each session can have many windows (listed on the bottom)
  • Each window can have many panes (the split panes you'll see)
  • Each new pane is a new bash prompt/terminal

To create a new session:

tmux

Now you can type C-b dand you'll dettach from the session. It's still running there, but you can exit you're SSH session now and attach again later… and all your beloved terminals will still be running 😍

To attach to a session you just created:

tmux a

To list existing sessions:

tmux ls

To attach to a specific session (see the first column from previous command, that's the id you need to use here. I'm using session zero):

tmux a -t 0

🤸🏻‍♀ That's super cool! But how can I move around?!

All commands start with C-b (C is the command key on Mac and thectrl key on Linux). So, basically always type the C-b prefix before almost every keystroke.

And here are the commands I use all the time and they should be enough for you to use tmux for weeks without having to worry much about it:

C-b c                     Create a new window
C-b | Split window vertically
C-b - Split window horizontally
C-b <arrow keys> Move between panes
C-b <h,j,k,l> Move between panes Vim-style
C-b <number> Go to window number n (listed at bottom)
C-b [ Enter in "scroll mode".
- Use arrows and page-down/up to move
- Type Enter to exit the mode.
C-b d Detach from session (to get back: tmux a)

😎 That's it?

Yep… but nope 😉 Tmux is an awesome piece of software with many, many more possibilities. Check its official Git repos for more and follow me on Twitter, I'll keep sharing tools and tricks I use daily as a Machine Learning Engineer and Researcher that can probably help you too! 👋

🤩 UPDATE: Wait, there's more!

From time to time I find more interesting commands, so I'll keep posting them here.

Sending the same command to all panes at once:

Let's say you have many panes open and you want to send the same commands to all of them:

C-b : setw synchronize-panes on

And to toggle it off:

C-b : setw synchronize-panes off

Removing other attached client:

You started your tmux and there's something wrong with the window size, it looks smaller than yours… maybe there's another client connected to your tmux running in a smaller window than yours! Just list the connected clients and remove the one you don't like:

C-b D

My panes are not aligned:

You can use the following command to iterate through many different layouts, maybe you're lucky and get your panes aligned as you wish:

C-b <space>

My windows are numbered wrong:

After a while, when you have removed windows in the middle, the numbers of your windows start to jump from n to n+x with x>1 . To re-enumerate the windows, just use:

C-b : move-window -r

I want to maximize one of the panes for a moment:

When you have too many panes open, it starts to get pretty hard to read on those smaller windows. To maximize the pane you have active, just toggle maximize/minize:

C-b z

--

--

Vilson Vieira

ML Engineer at Anything.World building the 3D AGI. Prev: SWE at Google, Mozilla. Passionate about AI. More at: https://void.cc & https://hackable.space