Beginner’s Guide to Tmux: Recommended Configuration, Plugins and Navigation Demo
This Tmux Tutorial will teach you how to install Tmux, how to install Tmux plugins, and configure your Tmux.conf
for maximum efficiency in terms of key bindings and more. It is based on the Office Hours hosted by Codementor Bruno Sutic, who is the creator of various popular Tmux plugins.
The text below is a summary done by the Codementor team and may vary from the original video and if you see any issues, please let us know!
What is Tmux?
Tmux is a terminal multiplexer, which means it will allow you to easily switch between several programs in one terminal, and it is especially handy when dealing with complex projects that require multiple terminals. Many developers have found Tmux an essential tool to boosting their productivity.
Why Tmux?
Tmux increases productivity for developers especially when working on bigger projects requiring multiple terminals. Personally I’ve never really explored all the possibilities of a tabbed terminal, but based on what I hear from friends who use it, it doesn’t take long for you to hit the limit on tabs that are comfortable to manage. You’d probably have 4 or 5 tabs open for a regular project, and if you have two projects, you may reach 10 tabs, and I think it’s a bit crowded to have so many tabs. Personally, I can have up to 70 terminals open, so I don’t think tabs will be manageable at that number.
In contrast, Tmux will allow you to have multiple windows in one terminal, window splits, sessions, and a persistent environment. It’s highly customizable, scriptable, and there are plugins that will extend the tmux even more, so it’s core features make managing many terminals a lot easier.
Installing Tmux
It’s really easy to install tmux. Just install brew and you haven’t already, and then use it to install tmux with
$ brew install tmux
However, apart from installing brew, you also need to
$ brew install reattach-to-user-namespace
to fix the pbpaste.
If you’re using a linux, installing is as easy as
$apt-get install –y tmux
Recommended configuration
All the tmux configurations are stored in the file ~/.tmux.conf
in your home directory. I’d really recommend beginners to remap the default “prefix” from ctrl-b to ctrl-a. The “prefix” is a key combination control that you have to press before triggering any of the tmux commands/operations. By default it is ctrl-b
, but we’d want to remap it to ctrl-a
. I’d also remap Caps Lock
to Ctrl
on a system level. Just google how to do it and you’ll find a solution no matter what operating system you have.
Basically, you can see now with these two prerequisites, you get a nice benefit to access these two keys easily. This is a recommended configuration by many people, and many people who use Vim also do this because Vim also requires them to use the ctrl
key a lot.
How to create multiple windows on tmux
Press Ctrl-a + C
, (I think C stands for create).
Now you have multiple windows; as you can see at the bottom of the screen, you have numbered windows 1,2,3.
Moving back and forth
prefix + p
, prefix + n
, and jump to a specific window with prefix + [number]
Splitting windows
vertical split: prefix + %
Horizontal split: prefix + “
As these are a little unusual choices of key combinations, I’ll show you how to remap those later.
Moving from one split window to another
With the key combination prefix +
, you can move from a split window to the next.
Creating sessions
You can think of sessions as a group of windows, and they’re really good for working on one project each. Create sessions with prefix + :new –s session_name
. Again, this is not very convenient, so you’ll learn how to easily remap this later.
Switching sessions
Prefix + S
Navigate sessions with j
, k
(or arrow keys
)
Detatching tmux
This is the killer feature of tmux. We can detach the current tmux with prefix + d
, and then get back to tmux and attach it with $tmux attach
. Tmux sessions persist until you restart or shut down your computer.
Advanced Configurations
There are some community standards you can look at, which is basically how everyone has configured their .tmux.conf
You can also learn other useful configurations by googling and reading a lot of blogs.
Installing configurations via plugins
All the plugins are on github.com/tmux-plugins/, but you can install my core configurations via https://github.com/tmux-plugins/tmux-sensible
It doesn’t do much aside from setting up your boilerplate for you so you don’t have to pollute your own config file with unnecessary things, and it also fixes several bugs related to Vim.
You can also remap your key bindings with pain control, where key bindings will be mapped in a more intuitive way. For example, prefix + |
splits the current pane horizontally and prefix + -
splits the current pane vertically, etc.
Lastly, the tmux sessionist is a lightweight tmux utility that makes it easier for you to switch and create sessions. It allows you to have automatic session-name completion so you can instantly switch sessions.
If you don’t know how to install a plugin, you can watch this video and follow along.
You install the plugins with prefix + I
. If you’re a beginner it can seem a bit overwhelming, but this is the short route.
Plugin Benefits
Here is what you will end up with after installing the plugins. If you’re a vim user, you’ll find this quite familiar.
Next Steps
As a beginner to Tmux, what are the next steps?
- look up tmux copy mode (this will allow you to scrollback, since you can’t scroll up in tmux)
- read the tmux documentation on the manual page.
- use tmux daily.
- I recommend reading the book “Tmux for Productive Mouse-Free Development”
And lastly, if you want to have more advanced features, but for more tmux plugins you can look through the plugins on https://github.com/tmux-plugins/