Go back to the main page

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

The .tmux.conf file in this article is located here.

  1. To start I open and vertically split a Tmux window opening ~./.tmux.conf within vim in the right pane.
  2. The ~/.tmux.conf file.
    This section is at the 1:04 mark in the screencast.
  3. I unbind the default Tmux prefix, Control-b, and assign the prefix to be the backtick key `.
  4. 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.
  5. Next, the <prefix>-L is assigned to take one back to the last active window.
  6. Vital binding that I use all the time.
    A demonstration of the last-window command binding is at the 2:29 mark.
  7. Set for 256 colors.
  8. Works good in OSX Terminal.app but might need to be changed for another OS.
  9. Set window numbering to start at 1
  10. Otherwise window numbering will start at 0.
  11. Enable the mouse.
  12. 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.

  13. Set the scroll history
  14. 30000 setting has worked well for me. Don't set this too low underestimating the large output of data files and stack traces.
  15. Configure the status bar
  16. You can certainly "trick" out the status bar but I prefer a simple one.
    Status bar is at the 5:01 mark.
  17. Set a "nested" prefix key in case you need to run a Tmux instance inside of a Tmux instance
  18. 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.
  19. If you are a vimmer then you must turn on vim bindings when in copy mode.
  20. I will have a separate installment on Tmux "copy mode".
  21. Set up copying to the system clipboard
  22. Please refer to this article for more on this topic. I also will be doing another episode on this.
  23. More vim-related settings this time map vim movement keys for moving around window panes.
  24. Moving around window panes efficiently is a must.
    Pane movement bindings are at the 8:37 mark.
    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.
  25. Next, are my mappings for resizing vertically split panes.
  26. 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.
      Pane resizing is at the 9:45 mark.
    • <prefix>-M-9 reverses the M-7 view
    • 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.

Comment on this article?

If you like this article and screencast go to the dedicated page for this series at http://minimul.com/teaches/tmux.