What is Tmux?

Tmux is a terminal multiplexer that allows you to run several panes, each running a different process, within one terminal window. It is really useful for running alongside Vim, so that you could feasibly spend all of your time programming solely in the terminal.

Here are a few examples where it rules:

Running rspec in the command line at the same time as using Vim to edit a spec and implementation file.

Or, as I am doing writing this blog, where I am editing blog-post .markdown files in one pane, running jekyll serve on localhost:4000 (allows me to see page rendered) and using one pane to run irb in the command line, for verison control using git or listing _post files.

Installing Tmux

To install tmux you must first install a package manager such as homebrew and then run brew install tmux.

Run tmux by entering tmux into the command line. It’s as easy as that! You will know that tmux is doing its thing because the title tmux will appear at the top of your window, and a coloured bar will appear at the bottom.

Split a Window into Panes

Now that you have tmux running, let’s have a little look at what it does. Tmux commands are prefixed by ctrl b. So in order to split a window horizontally into two panes type ctrl b and then ". To split that pane vertically in two, hit ctrl b and then %. How cool is that!

Understanding Tmux Objects

Now we have some split panes in tmux, it is important to know what we are looking at. The objects in tmux are called Session, Window and Pane. The Session is the session in which tmux is run. You began it when you typed tmux into the command line. Running only one Session per terminal shell is advisable. Each Session contains a Window. The Window is the view of all your processes. It is split into Panes. Each Pane within a Window usually runs a different process.

Tmux Commands

Below is a list of some commands in tmux. Each command begins with the prefix, which currently is ctrl b.

Command Action Command Action
prefix c new window prefix , name window
prefix w list windows prefix f find window
prefix & kill window prefix . move window
prefix % split pane horizontal prefix " split pane vertical
prefix o swap panes prefix q show pane numbers
prefix x kill pane prefix [SPACE] toggle layouts
prefix d detach prefix t big clock
prefix ? list shortcuts prefix : prompt

You may have noticed that it is a little laborious using ctrl b as your prefix, as your hand needs to continuously move away from the home range on your keyboard. We are going to fix this problem, and to do that we must do some reconfiguration.