Skip to content
lglenn edited this page Dec 8, 2011 · 12 revisions

Notes on tmux

This is not intended to be a tutorial or replacement documentation for tmux; it's my own list of things that I have found to be helpful when using tmux, albeit maybe spruced up a bit for consumption by someone that's not me.

tmux is a pretty powerful package, spending a little time with man tmux will undoubtedly uncover a few things that you'll find to be really helpful that I haven't outlined here.

Prefix Key

Note: If you don't read this, very little of the rest of this document will work / make sense.

All tmux commands are invoked by hitting a prefix key, then a command. By default, the prefix key is control-b (C-b). You'll quickly find that that's an awkward key combination. I prefer to use C-a as the prefix key instead -- it's far easier to reach.

For the rest of this document, I'll be using C-a to mean "whatever you have set as the prefix key".

To change the default keybinding, add the following to your .tmux.conf file (it's in your home directory; if it's not there, create it).

# Make C-a the prefix
set-option -g prefix C-a
unbind-key C-b
bind-key C-a send-prefix 

Commands

Most tmux commands have a key binding, but all commands have a name, and an be invoked by hitting C-a :, which will give you a command prompt in the status bar. Enter the name of a command, say, list-sessions, and hit enter. C-a ? lists all commands that have a keybinding. C-a : help <command> will give you the help text for that command. There's tab-completion so you don't have to type the whole name (e.g. list-s<tab> will expand to list-sessions).

Sessions

A session contains one or more windows. A session has a name, visible to the outside world.

Attaching to Sessions

To attach to a running tmux session (from outside tmux), do tmux attach. That will plop you back into the session you were in when you detached. If you have more than one session running, and want to attach to a session that isn't the one you detached from, do tmux attach -t <session name>.

Naming Sessions

C-a $ allows you to (re)name your session. If you don't name your session, it'll be given a numeric name.

Listing Sessions

From outside tmux: tmux ls From inside: C-a s

Switching Sessions

Unlike GNU Screen, tmux gives you the ability to switch your active session without leaving the program. Kind of a nice side-effect of tmux's server/client architecture. C-a s gives you an interactive list of sessions. C-a L switches you to the last session (it's the session equivalent of C-a l, which switches you to the last window).

Windows

A window is one "screen"; you can have multiple windows in a session, but you can only see one window at a time. Windows are numbered, 0-n, and have names. The status bar, at the bottom of the screen, has the name of the session in square brackets, followed by the name of each window.

Naming Windows

C-a , lets you rename the curent window. By default, the curent window has the name of the currently running process (e.g. bash, vim, man...)

Switching Windows

C-a l switches to the last window you were in -- it's like that button on the TV remote.

C-a n goes to the next window.

C-a p goes to the previous window.

C-a <number>, where number is the number of a window, goes to that window.

This is a really cool one...

C-a f prompts you for a search string. Hit enter, and you get popped to the window that contains that text. Case-sensitive, though. So, say you have a bunch of windows going, and one of them is tailing a web server access log. You want to go to that window, but you can't remember off the top of your head which window it is. Just hit C-a f POST, and you'll get popped to where you want to be (assuming that there are POST requests in the log).

Panes

A window contains one or more panes. You can split windows into panes, and panes can in turn be split. Panes don't have names, but they do have numbers -- hitting C-a q will pop a pane number on top of each pane.

Switching Panes

C-a ; switches to the last pane you were in on this window. Mnemonic: think of ';' as a lesser 'l'. They kind of look the same. C-a o switches to the next pane in the current window. C-a <arrow> switches to the next pane in the direction of that arrow. If you hit another arrow key quickly enough, you can keep moving. E.g. C-a <down> <left> will move you down one and one to the left, as long as you hit the down and the left within a second or so of each other.

Splitting Panes

C-a % splits a window (or pane) vertically (mnemonic: think of the % as a picture of a split window, with something on each side) C-a " splits a window (or pane) horizontally (mnemonic: I really can't think of one)

Custom: I find the default key bindings to be difficult to remember. Add this to your .tmux.conf file for more intuitive behavior:

bind-key _ split-window
bind-key | split-window -h

I use the underscore rather than a dash for the horizontal split so that both split commands require the shift key.

Rearranging panes

C-a C-o rotates the panes. The rotation behavior is pretty difficult to predict, and realistically, you wouldn't want to do it with more than two panes. So think of it as 'when I have two panes in the current window, and I want to swap them'.

Breaking Panes Out on Their Own

To break a pane out into its own window, use C-!. Reversing that operation is a little tricky -- tricky enough that I won't go into it here.

Laying Out Panes

tmux has a few built-in layouts for a multiple-pane window. For example, evenly spaced vertical panes, one big pane across the top and the rest evenly split across the bottom, etc. To cycle through layouts, use C-a <space>.

Copy-Paste

C-a # lists all the paste buffers C-a = gives you an interactive listing of the paste buffers; scroll to the one you want and hit enter to paste.

Sample Config File

Stick this in your home directory, in a file named .tmux.conf.

# Make C-a the prefix key
set-option -g prefix C-a
unbind-key C-b
bind-key C-a send-prefix

# Bind the commands C-b | and C-b _ to split window;
# it makes more sense than the default % and " bindings.  
bind-key | split-window -h
bind-key _ split-window

Screen/tmux Cheat Sheet

http://www.dayid.org/os/notes/tm.html