Increased Developer Productivity with Tmux, Part 2: ~/.tmux.conf

This article is over 2 years old. Proceed with caution.

Regards ♨ – Minimul

The heart & soul of the Tmux: .tmux.conf

In Part 1 I displayed in 5 minutes some of the benefits of Tmux or the "why" of wanting to use Tmux for software development. In this installment, I want to start getting to the "how" of using Tmux. To do that I must start with configuring Tmux via the ~/.tmux.conf file.

To live reload .tmux.conf setting changes do <prefix> <colon> and type source-file ~/.tmux.conf

I unbind the default Tmux prefix, Control-b, and assign the prefix to be the backtick key `.

Customizing the prefix key.

Be sure to use these 3 lines exactly as they appear if you also want to use the backtick key as your prefix. These lines ensure that you can also type the ` character when desired. To type the ` character you hit the backtick key twice.

The 'prefix' is the key that initiates Tmux or precedes a Tmux command. By default the prefix is Control-b. To hit Control-b all the time is cumbersome so I assign just a single key as the prefix.

Next, the <prefix>-L is assigned to take one back to the last active window.

Vital binding that I use all the time.

A demonstration of the last-window command binding is at the 2:29 mark.

Set for 256 colors.

Works good in OSX Terminal.app but might need to be changed for another OS.

Set window numbering to start at 1

Otherwise window numbering will start at 0.

Enable the mouse.

Enhanced mouse support.

Minimul says —

I don't use the mouse much at this stage but from time to time I do for a simple clipboard copy. If you are getting started with Tmux don't feel like you have to be mouse-free right away. Use the mouse or other touch device liberally so as not to take too much of a productivity hit while learning. Over time you will use the keyboard for almost everything console related.

Set the scroll history

30000 setting has worked well for me. Don't set this too low underestimating the large output of data files and stack traces.

Configure the status bar

You can certainly "trick" out the status bar but I prefer a simple one.

Set a "nested" prefix key in case you need to run a Tmux instance inside of a Tmux instance

To send a Tmux command to nested window you would type <prefix>-a first.

In practice when a nested scenario pops up for me is when I am doing system admin on a Linux box. However, in that case I just use screen because it is easy to install or already installed on the server. For small system admin tasks screen is totally fine. Tmux shines on more advanced usage.

If you are a vimmer then you must turn on vim bindings when in copy mode.

I will have a separate installment on Tmux "copy mode".

Set up copying to the system clipboard

Please refer to this article for more on this topic. I also will be doing another episode on this.

More vim-related settings this time map vim movement keys for moving around window panes.

The previously mentioned vim bindings were for copy mode. These bindings are simply activated using <prefix>-h , for example, to move to the left pane from the right.

Next, are my mappings for resizing vertically split panes.

A vertically split window is my most common view so I have bindings for quickly resizing the panes.

The 'M' stands for 'Meta key'. I use the option key in Terminal.app as my meta key. To do this in Terminal.app you must go to Terminal -> Preferences -> Settings tab -> and check "Use option as meta key".

This should be the case for OSX 10.7 and up.

For example, <prefix>-M-7 makes the -t 1 pane (or target pane 1 or the right pane) 90 lines of width.

This view enables me to see more when there is a lot of word-wrapping going on in the right pane.

This view is for when there is too much word wrapping in the left pane.

<prefix>-M-1 is a Tmux built-in binding and will even up the vertical panes.

Called 'even-horizontal' oddly enough.

That concludes installment 2. The .tmux.conf file

Customizing Tmux is a must for increasing your productivity with the tool. My .tmux.conf is a good starting point but study what others are putting in theirs. Keep sharpening your Tmux "chainsaw" but making note of commands you run often that don't have customized shortcuts and add them. Remove bindings and configurations that in the end you don't really use, keeping the file purposeful. Stay tuned for Part 3, which I will explain Tmux sessions. While you are waiting for the article check out the screencast that is already baked.