loading...
Cover image for Give Your Terminal Super Powers: tmux Cheatsheet!

Give Your Terminal Super Powers: tmux Cheatsheet!

jacobherrington profile image Jacob Herrington (he/him) Updated on ・4 min read

tmux is an application that I use in my terminal to manage several programs running at once. I've used it on Linux and Mac, it's one of the first things I install on a new computer along with Zsh and asdf.

The tmux wiki refers to tmux as a "terminal multiplexer;" basically, it lets you run several programs in one terminal window (and do some other really cool stuff).

It's one of those productivity tools that takes a certain amount of upfront investment to become comfortable. It's not quite as hard to get used to as Vim, but you do have to remember a handful of hotkeys.

Installing tmux

If you want to get your hands dirty with tmux, you'll have to pop open a terminal window and install it.

If you're using Ubuntu, you can install it with a simple sudo apt-get install tmux.

For those of you using Mac OS, you can install tmux with brew install tmux.

I haven't done development on a Windows machine in years, so I'm not sure how to get it running in that environment. If someone does, please leave a comment so I can link to it here, thanks!

Leader key

In tmux, pretty much every command starts out with the Leader Key, sometimes also called the prefix. By default, you have to press ctrl + b.

For most tmux commands, you'll press the leader key, then the hotkey for the command. Unlike many hotkeys, you don't need to keep the leader key held down while pressing the hotkey.

Sessions

Starting a tmux session

tmux sessions are the interface for using tmux. When you start your terminal, you'll need to launch a tmux session.

This is easy, just type tmux into your terminal, and you're off!

Creating a named session

Sometimes it is useful to give a tmux session a name, so that you can detach from it, and re-attach to it later.

tmux new -s some-session-name

Renaming a session

ctrl + b $

Detaching from a session

You can detach from a session and return to your standard shell without closing the session. This allows you to pick up your work later.

ctrl + b d

Listing existing sessions

Alt Text

You can list existing sessions by name with:

tmux ls or with tmux list-sessions

Attaching to a session

Once you've detached from a session, you can pick up where you left off by attaching to it.

Attach to the most recent session:

tmux a

Attach to a session by name:

tmux a -t some-session-name

If you currently attached to a session you can hop between sessions too.

Attach to the previous session:

ctrl + b (

Attach to the next session:

ctrl + b )

Kill a session

tmux kill-ses -t some-session-name

Kill all other sessions

If you want to kill all the sessions other than the one you are currently using, tmux makes that super simple:

tmux kill-ses -a

Panes

Alt Text

This is the most widely used feature of tmux. When you want a terminal with several windows running different processes, for example: a server, git, and Vim. You'd use a few panes.

The basics of pane splitting are easy!

Split a pane vertically

ctrl + b %

Split a pane horizontally

ctrl + b "

Navigating panes

You can navigate between your panes with the arrow keys. This is the most basic way of moving across your window:

ctrl + b
ctrl + b
ctrl + b
ctrl + b

Jump to the most recent pane

ctrl + b ;

Jump to next pane

ctrl + b o

Close current pane

ctrl + b x

Show pane numbers

Panes can be identified by numbers, you can get a list of those numbers with this shortcut:

ctrl + b q

Swap to a pane by number

ctrl + b q 0 (replace 0 with preferred pane number)

Resize current pane

This is one of the few cases in which you should hold the leader key down instead of releasing it!

ctrl + b + ←
ctrl + b + ↑
ctrl + b + →
ctrl + b + ↓

Move the current pane

To the right:

ctrl + b }

To the left:

ctrl + b {

Windows

If you need a new set of panes, you can create a window. A window is kind of like a tab.

Convert a pane into a window

ctrl + b !

List all windows

Alt Text

ctrl + b w

Select window by number

ctrl + b 0 (replace 0 with preferred window number)

Create a new window

ctrl + b c

Navigate to the previous window

ctrl + b p

Navigate to the next window

ctrl + b n

Close the current window

ctrl + b &

Command mode

Like Vim, tmux has a command mode.

To start command mode, use this:

ctrl + b :

Get help

ctrl + b ?

This is a cheatsheet for me, but hopefully, others find it useful. I'll probably expand it as I think of additional shortcuts I use frequently.

If there is a tmux shortcut you use frequently, feel free to add it in the comments!

There's more...

I'm writing a lot of articles these days, I run a podcast, and I've started sending out a newsletter digest about all of the awesome stories I'm hearing.

You can also follow me on Twitter, where I make silly memes and talk about being a developer.

Discussion

pic
Editor guide
Collapse
schasse profile image
Sebastian Schasse

Great post!

I'm using the terminal a lot and am usually very lazy with using the mouse^ That's why I'm using easymotion a lot. Unfortunately, there was no easymotion plugin for tmux and I wrote one myself. Check it out github.com/schasse/tmux-easymotion

Collapse
jacobherrington profile image
Jacob Herrington (he/him) Author

That's cool. 👀 I'll take a look!

Collapse
saturniusmons profile image
Shane

My 'favourite' command is ctrl+b z to zoom a pane in or out.

I have set-option -g mouse in my ~/.tmux.conf so I can click on a pane and it is magically in focus and for copy/pasting

My only pain point is I want to be able to do what I do in screen and that is detach a pane and let it run in the background whilst I do other things, so I can put my IRC panes away when I'm trying to work!

Collapse
rhymes profile image
rhymes

Great overview.

A note for macOS users: the modifier shortcut in tmux installed by brew install tmux is Ctrl-a, not Ctrl-b.

Collapse
jacobherrington profile image
Jacob Herrington (he/him) Author

Great catch, molte grazie Rhymes!

Collapse
puritanic profile image
Darkø Tasevski

I would also recommend this tmux configuration, both for beginners and experienced devs:

github.com/gpakosz/.tmux

I've started using it with the intention of tailoring it to my own needs but instead did just some minimal changes, as it's really great config.

Collapse
alocquet profile image
Arnaud

Thx for this post.
I have seen an error on Split pane horizontaly shortcut : CTRL+b % instead of CTRL+b "

Collapse
jacobherrington profile image
Collapse
cogoo profile image
Colin Ogoo

Tmux paired with Tmuxinator is a dream!

Collapse
jacobherrington profile image
Jacob Herrington (he/him) Author

I've never used Tmuxinator. Sounds intense. I'll search for it later! 😋

Collapse
awwsmm profile image
Andrew (he/him)

tmux is one of those things that -- along with Git -- seemed completely incomprehensible the first time I encountered it. I'll have to give it another shot, using your guide.

Thanks, Jacob!

Collapse
jacobherrington profile image
Jacob Herrington (he/him) Author

It's more intimidating than it should be. You can learn two or three hotkeys and benefit from it. Start slow and don't worry if it takes you a few weeks for the shortcuts to feel natural!

Collapse
ujwaldhakal profile image
ujwal dhakal

I have been using terminator for same

Collapse
jacobherrington profile image
Jacob Herrington (he/him) Author

I haven't used terminator, but I know some people like it a lot. It's a good alternative, I think. 😁

Collapse
ujwaldhakal profile image
Collapse
sebbestune profile image
Sebastian Lindgren

Great overview!

Collapse
prashantsengar profile image
Prashant Sengar

Thanks Jacob. This was really a very nice guide for introduction to tmux. I will give it a try.

Collapse
jacobherrington profile image
Collapse
lucianobarauna profile image
Luciano Baraúna

I've been using tmux for a while and only got compliments :-).
And after a while I started using byobu.org/ which is a handy hand facilitating tmux shortcuts