Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Cover image for Give Your Terminal Super Powers: tmux Cheatsheet!
Jacob Herrington (he/him)
Jacob Herrington (he/him)

Posted on • Edited on

     

Give Your Terminal Super Powers: tmux Cheatsheet!

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 withZsh andasdf.

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 simplesudo apt-get install tmux.

For those of you using Mac OS, you can install tmux withbrew 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 pressctrl + 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 typetmux 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 + bd

Listing existing sessions

Alt Text

You can list existing sessions by name with:

tmux ls or withtmux 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 + bo

Close current pane

ctrl + bx

Show pane numbers

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

ctrl + bq

Swap to a pane by number

ctrl + bq0 (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 + bw

Select window by number

ctrl + b0 (replace 0 with preferred window number)

Create a new window

ctrl + bc

Navigate to the previous window

ctrl + bp

Navigate to the next window

ctrl + bn

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 writinga lot of articles these days, I run apodcast, and I've started sending out anewsletter digest about all of the awesome stories I'm hearing.

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

Top comments(19)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss
CollapseExpand
 
schasse profile image
Sebastian Schasse
  • Location
    Berlin
  • Work
    IT Team Lead at GapFish
  • Joined

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 outgithub.com/schasse/tmux-easymotion

CollapseExpand
 
jacobherrington profile image
Jacob Herrington (he/him)
I used to work on this website!https://bsky.app/profile/jacobherrington.dev
  • Education
    Self-taught
  • Joined

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

CollapseExpand
 
saturniusmons profile image
Shane
  • Joined
• Edited on• Edited

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

I haveset-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 inscreen 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!

CollapseExpand
 
rhymes profile image
rhymes
Such software as dreams are made on.I mostly rant about performance, unnecessary complexity, privacy and data collection.
  • Joined

Great overview.

A note for macOS users: the modifier shortcut in tmux installed bybrew install tmux isCtrl-a, notCtrl-b.

CollapseExpand
 
jacobherrington profile image
Jacob Herrington (he/him)
I used to work on this website!https://bsky.app/profile/jacobherrington.dev
  • Education
    Self-taught
  • Joined

Great catch, molte grazie Rhymes!

CollapseExpand
 
puritanic profile image
Darkø Tasevski
My profession is engineering
  • Location
    Blackwater Park
  • Joined

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.

CollapseExpand
 
alocquet profile image
Arnaud
  • Joined

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

CollapseExpand
 
jacobherrington profile image
Jacob Herrington (he/him)
I used to work on this website!https://bsky.app/profile/jacobherrington.dev
  • Education
    Self-taught
  • Joined

Thanks!!!

CollapseExpand
 
cogoo profile image
C.OG
@Solana 🦀 🟠
  • Location
    London, UK
  • Joined

Tmux paired with Tmuxinator is a dream!

CollapseExpand
 
jacobherrington profile image
Jacob Herrington (he/him)
I used to work on this website!https://bsky.app/profile/jacobherrington.dev
  • Education
    Self-taught
  • Joined

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

CollapseExpand
 
awwsmm profile image
Andrew (he/him)
Got a Ph.D. looking for dark matter, but not finding any. Now I code full-time. Je parle un peu français.
  • Email
  • Location
    Ottawa, Canada
  • Education
    Ph.D. in [Astroparticle] Physics
  • Pronouns
    he / him
  • Work
    Principal Consultant at Improving
  • Joined

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!

CollapseExpand
 
jacobherrington profile image
Jacob Herrington (he/him)
I used to work on this website!https://bsky.app/profile/jacobherrington.dev
  • Education
    Self-taught
  • Joined

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!

CollapseExpand
 
ujwaldhakal profile image
ujwal dhakal
MMA Fighter, Boxer, Part time doctor, teacher, stunner, seasonal model, heavy weight lifter, athlete well i am not any of them.

I have been using terminator for same

CollapseExpand
 
jacobherrington profile image
Jacob Herrington (he/him)
I used to work on this website!https://bsky.app/profile/jacobherrington.dev
  • Education
    Self-taught
  • Joined

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

CollapseExpand
 
ujwaldhakal profile image
ujwal dhakal
MMA Fighter, Boxer, Part time doctor, teacher, stunner, seasonal model, heavy weight lifter, athlete well i am not any of them.

yes it is

CollapseExpand
 
sebbestune profile image
Sebastian Lindgren
Finding my path in life. Already tried $PATH. Enjoy learning about new programming languages, Linux and Vim.
  • Location
    Finland
  • Joined

Great overview!

CollapseExpand
 
prashantsengar profile image
Prashant Sengar
I am a learner and a worker
  • Location
    Greater Noida
  • Education
    Computer Science and Engineering, Bachelor of Technology
  • Work
    Student
  • Joined

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

CollapseExpand
 
jacobherrington profile image
Jacob Herrington (he/him)
I used to work on this website!https://bsky.app/profile/jacobherrington.dev
  • Education
    Self-taught
  • Joined

Glad you enoyed it!

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

I used to work on this website!https://bsky.app/profile/jacobherrington.dev
  • Education
    Self-taught
  • Joined

More fromJacob Herrington (he/him)

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp