Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Getting Started with tmux
Getting Started with tmux

Getting Started with tmux: Maximize your productivity by accessing several terminal sessions from a single window using tmux

Arrow left icon
Profile Icon Victor Quinn
Arrow right icon
Free Trial
Full star icon Full star icon Full star icon Full star icon Half star icon 4.3 (8 Ratings)
Paperback Sep 2014 148 pages 1st Edition
eBook
Can$20.99 Can$30.99
Paperback
Can$37.99
Subscription
Free Trial
Arrow left icon
Profile Icon Victor Quinn
Arrow right icon
Free Trial
Full star icon Full star icon Full star icon Full star icon Half star icon 4.3 (8 Ratings)
Paperback Sep 2014 148 pages 1st Edition
eBook
Can$20.99 Can$30.99
Paperback
Can$37.99
Subscription
Free Trial
eBook
Can$20.99 Can$30.99
Paperback
Can$37.99
Subscription
Free Trial

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing
Table of content icon View table of contents Preview book icon Preview Book

Getting Started with tmux

Chapter 2. Configuring tmux

Now that we've had our first taste of tmux, let's dig into our first topic in greater detail. tmux is a very powerful program and thankfully one that is also highly configurable. You can change almost anything about its behavior, from the way it looks and feels to the commands it executes on load; you can even configure every key combination to which tmux responds.

In this chapter, we will cover various ways to configure tmux to customize and optimize it for your workflow. We will build a sample configuration that can be used to make tmux a bit cleaner, prettier, and more useful.

We will be unable to cover every minute detail or configuration option, but we will hit the most common ones and set you up with the knowledge and toolset to be able to tackle any configuration you desire. In this chapter, we will discuss the following:

  • Using the set-option command
  • Creating a tmux configuration file
  • Emacs or vi mode
  • Enabling mouse modes
  • Changing the status...

Using the set-option command

The main way in which options are set and configured within tmux is through the appropriately named set-option command.

This command can be called on its own to set an option temporarily. However, most of the time, we will use it to set options within a tmux configuration file so each time we launch tmux, the options are set the way we would like.

For a taste of using the set-option command to set an option temporarily, open a terminal window and launch tmux; alternatively, if you've been following along through Chapter 1, Jump Right In, just type the following command in the window:

$ tmux set-option status off

Once you do this, the status bar will disappear! This setting is only temporary, so if you leave it as is, end the session, and restart tmux or create a new session, it will not load this setting. In other words, a status bar will appear.

What you have done is that you've told tmux to set the option status to a value of off. You can use this command...

Creating a tmux configuration file

In order to keep the settings around after restarting tmux, we will create a configuration file that will include all the information about what options we want to set and to what values.

Like many other Unix-based utilities, configuring tmux is as simple as creating a file with the name .tmux.conf in your home directory.

However, unlike many other configuration files, a tmux configuration file does not contain some kind of specific configuration language for the program, rather it consists of a series of tmux commands that are run, in order, when tmux starts up. Most of the commands we'll see are simple set-option commands similar to the commands we played with in the previous examples. Let's create and start building our configuration file:

$ cd ~
$ touch .tmux.conf

Open this newly created file in your favorite text editor and we're ready to rock!

Tip

Like with most Unix-based utilities, this file in your personal directory contains the configuration...

Emacs or vi mode

As we discovered in Chapter 1, Jump Right In, tmux tries to help developers by providing two sets of key bindings, one each for the two most widespread text editors. If you swing one way or the other, this is likely to be one of the first things you'll want to change to make tmux feel right for you.

The default for tmux is to use the Emacs mode keys, so if you are an Emacs user, you may be all set. tmux also tries to help out and might, based on environment variables, switch to one group or the other by default. To check which mode tmux is currently in, run the following command:

$ tmux show-options -g | grep key

You should get an output that looks something similar to the following command:

$ status-keys emacs

If you are in the mode you'd like to be in, you can do nothing. If you are in the wrong mode though, you would most likely want to add the following couple of lines to your .tmux.conf file, obviously choosing the appropriate editor:

set-option -g status-keys...

Enabling mouse modes

First, it's worthwhile to note that one of the main benefits of tmux is to obviate the need to reach for your mouse as often as you otherwise would. So, some purists would balk at the notion of enabling mouse modes for tmux.

That said, it is often rather convenient to use the mouse to scroll, select text, resize panes, choose an option from a list, and more. And yes, tmux allows you to do all of that with the mouse. These features are disabled by default so to enable them, we need to add the following lines to our .tmux.conf (either Emacs or vi):

set-window-option -g mouse-mode on
set-option -g mouse-select-window on
set-option -g mouse-select-pane on
set-option -g mouse-resize-pane on

This will enable mouse functionality in all of the ways we described. We haven't yet dealt with panes, but when we touch on that in Chapter 3, Sessions, Windows, and Panes, it will be more apparent how using the mouse to resize them will be incredibly convenient.

Using the set-option command


The main way in which options are set and configured within tmux is through the appropriately named set-option command.

This command can be called on its own to set an option temporarily. However, most of the time, we will use it to set options within a tmux configuration file so each time we launch tmux, the options are set the way we would like.

For a taste of using the set-option command to set an option temporarily, open a terminal window and launch tmux; alternatively, if you've been following along through Chapter 1, Jump Right In, just type the following command in the window:

$ tmux set-option status off

Once you do this, the status bar will disappear! This setting is only temporary, so if you leave it as is, end the session, and restart tmux or create a new session, it will not load this setting. In other words, a status bar will appear.

What you have done is that you've told tmux to set the option status to a value of off. You can use this command to set...

Creating a tmux configuration file


In order to keep the settings around after restarting tmux, we will create a configuration file that will include all the information about what options we want to set and to what values.

Like many other Unix-based utilities, configuring tmux is as simple as creating a file with the name .tmux.conf in your home directory.

However, unlike many other configuration files, a tmux configuration file does not contain some kind of specific configuration language for the program, rather it consists of a series of tmux commands that are run, in order, when tmux starts up. Most of the commands we'll see are simple set-option commands similar to the commands we played with in the previous examples. Let's create and start building our configuration file:

$ cd ~
$ touch .tmux.conf

Open this newly created file in your favorite text editor and we're ready to rock!

Tip

Like with most Unix-based utilities, this file in your personal directory contains the configuration for...

Emacs or vi mode


As we discovered in Chapter 1, Jump Right In, tmux tries to help developers by providing two sets of key bindings, one each for the two most widespread text editors. If you swing one way or the other, this is likely to be one of the first things you'll want to change to make tmux feel right for you.

The default for tmux is to use the Emacs mode keys, so if you are an Emacs user, you may be all set. tmux also tries to help out and might, based on environment variables, switch to one group or the other by default. To check which mode tmux is currently in, run the following command:

$ tmux show-options -g | grep key

You should get an output that looks something similar to the following command:

$ status-keys emacs

If you are in the mode you'd like to be in, you can do nothing. If you are in the wrong mode though, you would most likely want to add the following couple of lines to your .tmux.conf file, obviously choosing the appropriate editor:

set-option -g status-keys emacs
set...

Enabling mouse modes


First, it's worthwhile to note that one of the main benefits of tmux is to obviate the need to reach for your mouse as often as you otherwise would. So, some purists would balk at the notion of enabling mouse modes for tmux.

That said, it is often rather convenient to use the mouse to scroll, select text, resize panes, choose an option from a list, and more. And yes, tmux allows you to do all of that with the mouse. These features are disabled by default so to enable them, we need to add the following lines to our .tmux.conf (either Emacs or vi):

set-window-option -g mouse-mode on
set-option -g mouse-select-window on
set-option -g mouse-select-pane on
set-option -g mouse-resize-pane on

This will enable mouse functionality in all of the ways we described. We haven't yet dealt with panes, but when we touch on that in Chapter 3, Sessions, Windows, and Panes, it will be more apparent how using the mouse to resize them will be incredibly convenient.

Changing the status bar


We learned a bit about the status bar in the last chapter when we discussed changing the session and window names. This status bar is highly customizable, and it's a great place to start learning about configuring tmux. We can change the status bar colors, what appears on the status bar, the alignment, and much more.

Modifying the background color of the status bar

Let's add an item to our configuration to change the color of the status bar. As we saw by jumping in, the default color of the status bar is a shade of green. Note that there happens to be a shade of green in our configuration as well, but it is likely a different color on your terminal unless you are using the same color scheme as we are.

Note

The authors are using a color scheme called Solarized. It is a color scheme that includes both dark and light variants and is optimized for the terminal and readability. It was developed by Ethan Schoonover and has gained quite a following in the tech community for...

Binding keys


Binding keys will allow you to change the keys and key combinations that tmux will recognize for any command. This also allows us to create new key combinations for existing commands or change the key binding for any existing keys used by tmux. It even lets you assign new key bindings to any command we can dream about.

The commands to which we can bind keys can even prompt for user input. There is no constraint on uniqueness, so we could bind multiple keys to issue the same command or bind no keys for a particular command.

What this all means is that while there is not an existing key combination available to reload the tmux source file, we can make up our own key combination and assign it to the rather lengthy source-file command so we don't have to type the whole thing each time we want to reload the configuration.

First, let's find a good key combination to bind for this command.

Viewing current bindings

Recall from the first chapter that we were able to see all of the current...

Unbinding keys


Now let's say there is a key binding that you want to remove for some reason. This is very easy; just add an unbind directive to your .tmux.conf file.

Say we wanted to unbind 0 from its default action of selecting window 0 for some reason. To do this, simply add the following code snippet to your configuration:

unbind 0

Note that there is no need to explicitly unbind a key before binding it to something else; every key can only have one binding. So, we find it rather rare to use this bit of utility, but it's nice to know it's there when you need it.

Status bar revisited


Last time we touched the status bar, we altered its colors, but we did not do anything to change its content. tmux allows us to change a lot of different aspects of the content of the status bar. We won't have an in-depth look at every possible configuration, but will explain the concept and show one example.

So, the status bar has three chunks basically:

  • status-left: This represents the stuff on the status bar on the left-hand side, including the current session

  • List of open windows: This appears in the middle by default

  • status-right: This represents the stuff on the status bar on the right-hand side, including the current date

Recall our status bar, which appears as shown in the following screenshot:

By default, status-left shows the name of the current session in brackets. We named our session tutorial, so status-left for us is [tutorial].

We can change these. They are just simple strings with some magic character pairs that tmux fills in based on what they mean. For...

Option types


Thus far, all of the options we have set had the -g flag. This means that the option applies globally. However, there are three types of options: server options, session options, and window options.

There are also multiple flags that indicate how a given option should affect or be affected. This sounds complex, but it's rather simple.

A server option will apply to any client that connects to tmux. Under the hood, when you type and run the tmux command the first time, tmux creates a server; then, it creates your client and connects to the server it started. This is the magic that allows you to detach your session, reattach it later, and have everything running as you left it because the tmux server keeps chugging in the background. So an option specified with the -s flag will apply to the server, meaning it will affect any clients that attach to it.

A session option will apply to the current session. This means that two clients could connect to the same server and each could have...

Left arrow icon Right arrow icon

Description

The book is intended for software developers, DevOps engineers, and other professionals who make heavy use of the terminal in their daily workflow. Some familiarity with the terminal is useful but no prior experience with tmux or other terminal multiplexers (such as GNU Screen) is required.

What you will learn

  • Increase productivity by using tmux rather than a mouse to switch between terminal windows
  • Persist sessions on remote machines over SSH with tmux, making it easy to resume right where you left off even if your connection is terminated
  • Learn how tmux can be used to create persistent dashboards for monitoring servers
  • Use tmux to manage multiple terminal windows from a single one
  • Maximize terminal productivity with tmux
  • Maintain the state even when a terminal window is closed with tmux
  • Configure tmux and customize it for your needs

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Sep 24, 2014
Length: 148 pages
Edition : 1st
Language : English
ISBN-13 : 9781783985166
Tools :

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing

Product Details

Publication date : Sep 24, 2014
Length: 148 pages
Edition : 1st
Language : English
ISBN-13 : 9781783985166
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
$19.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
$199.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just Can$6 each
Feature tick icon Exclusive print discounts
$279.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just Can$6 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total Can$ 161.97
Git Version Control Cookbook
Can$61.99
SELinux Cookbook
Can$61.99
Getting Started with tmux
Can$37.99
Total Can$ 161.97 Stars icon

Table of Contents

9 Chapters
1. Jump Right In Chevron down icon Chevron up icon
2. Configuring tmux Chevron down icon Chevron up icon
3. Sessions, Windows, and Panes Chevron down icon Chevron up icon
4. Manipulating Text Chevron down icon Chevron up icon
5. Diving Deeper Chevron down icon Chevron up icon
6. tmux for SSH, Pair Programming, and More Chevron down icon Chevron up icon
7. Using Other Tools with tmux Chevron down icon Chevron up icon
A. Appendix Chevron down icon Chevron up icon
Index Chevron down icon Chevron up icon

Customer reviews

Most Recent
Rating distribution
Full star icon Full star icon Full star icon Full star icon Half star icon 4.3
(8 Ratings)
5 star 62.5%
4 star 12.5%
3 star 12.5%
2 star 12.5%
1 star 0%
Filter icon Filter
Most Recent

Filter reviews by




KS Sep 10, 2021
Full star icon Full star icon Full star icon Full star icon Full star icon 5
tmux は、単一の端末アプリを多重化して使う素晴らしいツールですが、あまりいい解説がありませんでした。テキスト中心で、表示がどうなっているのか、使っている概念が何なのか、想像するのが難しかったのですが、このあたりがスクリーンショットを使ってわかりやすく解説してあります。
Amazon Verified review Amazon
Daniel Demuth Jul 26, 2018
Full star icon Full star icon Full star icon Full star icon Full star icon 5
This book is a nice introduction to tmux, it explains in clear words and can be understood easily. While I am a retired IT guy I did not know tmux at all.
Amazon Verified review Amazon
Andrew C. Dec 17, 2017
Full star icon Full star icon Full star icon Empty star icon Empty star icon 3
If you are looking for a concise book then this is not for you. The author has a tendency to tell you the important bits after you need to know them. On the positive side, having filtered out the verbiage, there is some good stuff in the book.
Amazon Verified review Amazon
Jerome Lanteri Jul 27, 2017
Full star icon Full star icon Empty star icon Empty star icon Empty star icon 2
That book is to short.Also it doesn't speak about option -t and group sessions (lake of information then ?).So if you reduce the number on pages by just the real content without borring and uninteresting pictures, you can divide the number of pages by 2 ou 3 !!!Then this is an exepensive book for so little content.Also, when speak about tmuxinator (very quickly... 3 pages who can be write in one or half one...Why not give the list of all the command you should use for config a pretty good personnalized session ?ok... i think that the autor was very lazy.I regret to buy this book.ALSO kindle format is not full implemented... you can not jump on page through an index... incredible.
Amazon Verified review Amazon
Kquinn03 Dec 12, 2014
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Most understandable, easy to follow TMUX programming how to I've ever seen.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

What is included in a Packt subscription? Chevron down icon Chevron up icon

A subscription provides you with full access to view all Packt and licnesed content online, this includes exclusive access to Early Access titles. Depending on the tier chosen you can also earn credits and discounts to use for owning content

How can I cancel my subscription? Chevron down icon Chevron up icon

To cancel your subscription with us simply go to the account page - found in the top right of the page or at https://subscription.packtpub.com/my-account/subscription - From here you will see the ‘cancel subscription’ button in the grey box with your subscription information in.

What are credits? Chevron down icon Chevron up icon

Credits can be earned from reading 40 section of any title within the payment cycle - a month starting from the day of subscription payment. You also earn a Credit every month if you subscribe to our annual or 18 month plans. Credits can be used to buy books DRM free, the same way that you would pay for a book. Your credits can be found in the subscription homepage - subscription.packtpub.com - clicking on ‘the my’ library dropdown and selecting ‘credits’.

What happens if an Early Access Course is cancelled? Chevron down icon Chevron up icon

Projects are rarely cancelled, but sometimes it's unavoidable. If an Early Access course is cancelled or excessively delayed, you can exchange your purchase for another course. For further details, please contact us here.

Where can I send feedback about an Early Access title? Chevron down icon Chevron up icon

If you have any feedback about the product you're reading, or Early Access in general, then please fill out a contact form here and we'll make sure the feedback gets to the right team. 

Can I download the code files for Early Access titles? Chevron down icon Chevron up icon

We try to ensure that all books in Early Access have code available to use, download, and fork on GitHub. This helps us be more agile in the development of the book, and helps keep the often changing code base of new versions and new technologies as up to date as possible. Unfortunately, however, there will be rare cases when it is not possible for us to have downloadable code samples available until publication.

When we publish the book, the code files will also be available to download from the Packt website.

How accurate is the publication date? Chevron down icon Chevron up icon

The publication date is as accurate as we can be at any point in the project. Unfortunately, delays can happen. Often those delays are out of our control, such as changes to the technology code base or delays in the tech release. We do our best to give you an accurate estimate of the publication date at any given time, and as more chapters are delivered, the more accurate the delivery date will become.

How will I know when new chapters are ready? Chevron down icon Chevron up icon

We'll let you know every time there has been an update to a course that you've bought in Early Access. You'll get an email to let you know there has been a new chapter, or a change to a previous chapter. The new chapters are automatically added to your account, so you can also check back there any time you're ready and download or read them online.

I am a Packt subscriber, do I get Early Access? Chevron down icon Chevron up icon

Yes, all Early Access content is fully available through your subscription. You will need to have a paid for or active trial subscription in order to access all titles.

How is Early Access delivered? Chevron down icon Chevron up icon

Early Access is currently only available as a PDF or through our online reader. As we make changes or add new chapters, the files in your Packt account will be updated so you can download them again or view them online immediately.

How do I buy Early Access content? Chevron down icon Chevron up icon

Early Access is a way of us getting our content to you quicker, but the method of buying the Early Access course is still the same. Just find the course you want to buy, go through the check-out steps, and you’ll get a confirmation email from us with information and a link to the relevant Early Access courses.

What is Early Access? Chevron down icon Chevron up icon

Keeping up to date with the latest technology is difficult; new versions, new frameworks, new techniques. This feature gives you a head-start to our content, as it's being created. With Early Access you'll receive each chapter as it's written, and get regular updates throughout the product's development, as well as the final course as soon as it's ready.We created Early Access as a means of giving you the information you need, as soon as it's available. As we go through the process of developing a course, 99% of it can be ready but we can't publish until that last 1% falls in to place. Early Access helps to unlock the potential of our content early, to help you start your learning when you need it most. You not only get access to every chapter as it's delivered, edited, and updated, but you'll also get the finalized, DRM-free product to download in any format you want when it's published. As a member of Packt, you'll also be eligible for our exclusive offers, including a free course every day, and discounts on new and popular titles.