How I use Tmux

I started using tmux because of its ability to split a window into a several panes and have a web-server running along with an opened console like this:

Session with two windows and two panes in the first window

I’ve been discovering more and more tmux features ever since, which helps me to improve my workflow and to be more productive.

Since there’s always someone who is one step behind, I decided to write this post and sell tmux to you.

Sessions, Windows and Panes

Session is a group of windows. Window consists of panes. Sessions and Windows can be named. You can have several sessions. This is especially useful if you work on several projects. In this case you can set up several workspaces and easily switch between them.

Command Line Interface

Everything tmux can do is accessible via its cli interface. It allows you to write a simple shell script that will prepare your working environment for you. I have one in my .bashrc, that starts all sessions I use.

Control Tmux from Other Apps

Tmux has a client-server architecture. So once you’ve started a server you can send commands to it. This could be really handy if you want to manipulate tmux from some other application.

For example you can use External REPL plugin for SublimeText to send code to a REPL. All what it does is it sends pieces of code to a tmux window named repl. That’s it. If you have tmux running in your system with a window named repl it will find it, paste selected code into it, and send return.

Sublime External REPL

Status Bar

Everything that you can print in a console you can have in your tmux status bar. Weather, Continuous Integration status, inbox counter, almost no limits there. In my config there are only current session name on the left and data on the right.

Using tmux via SSH

It happens sometimes that you’ve ran some heavy task via ssh and internet went down. But if you run in in a tmux session it will continue even after disconnect. Because it will continue running on a tmux server. So after you reconnect and attach to a session you will see that everything’s fine.

I find extremely handy tmux’s multi-window nature in this case. I don’t need to login several times to the server. I just need to login once, start tmux and have as many windows as I need.

Tmux for Pair Programming

That is something I haven’t tried yet. But you can have your buddy connected to your laptop, attached to your session and writing code in your Vim!

Where to Start

There are a plenty of articles, screencasts and talks on the internet. Though setup process wasn’t straightforward for me. It took some time to have everything working. If you like, you can start with my tmux config I put together from a various sources.

On Mac I’d recommend to use tmux with iTerm2, so you configure a mouse for switching widows and panes, scroll buffers, copy text. I also have a key binding for switching between tmux windows with cmd+shift+{ like I do in browser and in SublimeText. I also have some settings to fix alt+arrows for jumping word by word.

I highly recommend you to give it a try if you are using console heavily in your day-to-day work. For me it fits so good in a process I even think to abandon SublimeText for Vim so I won’t be switching between iTerm and a text editor.

One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.