Getting Into Tmux

I had tried out screen on OS X and failed to make it stick with me as a day to day tool, but recently I started using tmux and can’t imagine going back. Some of the things that set tmux apart are it’s ability to do vertical splits w/o any screwy patches and scriptability.


So lets start with the basics, installation.

brew install tmux

You can surely install this other ways, but using homebrew is super easy and you should be using it anyway.

Settling In

Like any tool there is some stuff that I got into the config file right away to make it feel more homey. First, I switched out the default command prefix C-b for C-a. From what I’ve read the only reason C-b is the default is so that it doesn’t conflict with scree. C-b is torture for your fingers though so there’s no reason to stick with that.

set-option -g prefix C-a

Next, because I use vim as my editor, I told tmux to us vi mode keys.

setw -g mode-keys vi

Finally, I setup some bindings so that I can move around splits using the vim movement keys.

bind h select-pane -L
bind j select-pane -D
bind k select-pane -U
bind l select-pane -R

That’s it. That’s everything in my ~/.tmux.conf right now. Like I said I just started with tmux so I’m sure my customizations will grow but as a vim user this is what I needed to make tmux feel more like home.

Basic Operation

As I got into using tmux there was definitely a point at which I learned just enough so that I was comfortable using it all the time and didn’t think to myself “Why am I using this, if I was using straight terminal I could do x so easily”.

Here’s the rundown of my most used commands…

Note: I use C-a in all the examples below, but if you have a different prefix set up substitute that for C-a.

Creating a new session from the command line:

tmux new -s my_session_name

Creating a new session from within a running session:

C-a :
new -s my_session_name

What’s cool here is that while in tmux you can hit C-a : and get a tmux command prompt and execute any of the normal tmux commands.

Attaching to running session:

tmux attach -t some_session_name

or if you know you only have one running session just:

tmux attach

Creating new windows while in a session:

C-a c

Naming your current window

C-a ,

Switching sessions:

C-a s

Entering copy-mode:

C-a [

A note on copy-mode… I kind of think of this as entering normal mode in vim.Being in copy mode allows you to move around the terminal just like normal mode in vim. To be honest, I’m pretty sure I’m not using copy-mode to it’s full potential yet. I mainly use it to scroll up to see things that have gone out of view in my terminal window.