Skip to content

Instantly share code, notes, and snippets.

@Fingel
Created November 13, 2015 17:36
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Fingel/89d2f86cf97922f8e734 to your computer and use it in GitHub Desktop.
Save Fingel/89d2f86cf97922f8e734 to your computer and use it in GitHub Desktop.
A tmux tutorial

Tmux Tutorial

Tmux stands for Terminal Multiplexer. It allows you to run multiple programs in the same terminal, detach from the terminal (while the programs continue to run) and re attach from a different terminal.

Start Tmux

tmux

Program name in the bottom left corner, bottom right corner has hostname, date, time. Besides that, it's just a regular terminal.

Try running top:

top

Now disconnect from the tmux session:

prefix d

Now let's re-attach:

tmux a

Windows

Let's create a new window

prefix c

Notice we now have two "tabs" in the bottom left. One for top and one for bash. We can switch between them using:

prefix Tab

Let's create yet another window:

prefix c

Now we have three windows. To switch to any window, use

prefix <num>

Where num is the number of the window. We can also use

prefix p and prefix n

To switch to the previous window, and the next window, respectively.

To close a window, exit like it's a normal shell. Alternatively you can kill a window using:

prefix &

Renaming and moving windows

I find it useful to rename windows to something other than the currently running program. To rename a window:

prefix ,

You can also move a window to a different number:

prefix .

Panes

Now the fun begins. Lets split our window vertically into 2 panes:

prefix v

We can then split or new pane horizontally:

prefix h

Notice how the borders are highlighted to show you which pane you are on.

To change panes, we can use the arrow keys:

prefix up prefix down prefix left prefix right

To go to the last used pane (like alt-tab):

prefix ;

You can move pans around by using:

prefix { prefix }

Resizing and layouts

Resize panes using:

prefix Alt+up prefix Alt+down prefix Alt+right prefix Alt+left

Or switch between predefined layouts:

prefix Alt+<num>

.tmux.conf

I've made some modifications to the stock tmux.conf to make it both easier to use and look nicer.

The default prefix of Ctrl+b is annoying. Let rebind it to `:

unbind C-b
set-option -g prefix `
bind-key ` send-preifx

The last line let's us still type a `, you just have to hit it twice.

The defauly keys " and % are pretty WTF for splitting windows. Let's rebind thos to v and h. Also tmux has weird definition of vertial and horizontal. I've switched them. YMMV.

bind h split-window -v
bind v split-window -h
unbind '"'
unbind %

Switching panes using the arrow keys. If you like vim you could chage these to hjkl:

bind Left select-pane -L
bind Right select-pane -R
bind Up select-pane -U
bind Down select-pane -D

Let's bind Tab to last-window so we get alt+tab like behavior. If you use panes more you could change this to last-pane:

bind Tab last-window

Enable mouse support. Controversial. Allows you to switch windows, panes and resize panes using the mouse. But then you must hold shift to select text using the terminal. Comment if you don't want these features:

set -g mouse on

The rest of the config changes the look of tmux. Trust me, it doesn't look this good without makeup.

This launches the tmux-resurrect plugin, which I will demo for you now:

run-shell ~/Downloads/tmux-resurrect/resurrect.tmux

Installing it is left as an excercize for the reader.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment