Introduction

Tmux has many advantages over screen and serves as a terminal multiplexer. This functionality is extremely practical and even essential once you’ve started using it.

Installation

  aptitude install tmux
  

Usage

To use tmux, simply launch it:

  tmux
  

Like screen, tmux uses a key combination to access its internal functions. By default, it’s “Ctrl+b” (which can be modified) that is used. To start, you can easily get help (don’t forget to press “Ctrl+b” before pressing any key):

DescriptionKeys
Get help?

Window Management

You can manage your windows as follows (don’t forget to press “Ctrl+b” before pressing any key):

DescriptionKeys
Create a new windowc
Get a list of open windowsw
Move to the next windown
Move to the previous windowp
Move to the last used windowl
Move to a window by its number0 1 2 3 4 5 6 7 8 9
Search in window buffersf then “window search name”
Rename the current window,
Force close a window&
Display timet

Split

You can split the screen in several ways:

DescriptionKeys
Horizontally split the screen"
Vertically split the screen%
Move to the previous pane{
Move to the next pane} or o
Move to the pane corresponding to the key← → ↑ ↓
Get pane numbersq
Change visual organization of panes[space]
Resize a paneAlt+(← → ↑ ↓)
Convert a pane from a split into a window!
Convert a window for integration into a split
_ -h: horizontally
_ -s 0.0: window 0 and pane 0
* -p 75: taking 75% of window
:joinp -h -s 0.0 -p 75

History

By default, Tmux keeps only 2000 lines of history. Here’s how to navigate:

DescriptionKeys
Scroll up through history↑↑ (PageUP)
Scroll down through history after scrolling up↓↓ (PageDOWN)
Select lines from history (after PageUP)[space] then (↑/↓)
Copy selection[enter]
Paste selection=

Sessions

Session management is something very practical. It’s always useful to be able to exit an SSH session and leave time-consuming tasks running, or to protect against network disconnections. That’s why when you’re in tmux, it’s possible to detach from your tmux:

DescriptionKeys
Detach from tmux sessiond
List tmux sessionss
Switch to next tmux session)
Switch to previous tmux session(

Then reattach later:

  tmux a
  

This command also allows multiple participants to see exactly the same thing.

Cheat Sheet

I’ve created a cheat sheet for those interested:

Customization

You can customize all kinds of things (I’ll let you read the man page as it’s so complete), and here’s my configuration:

  # Tmux configuration
# Pierre Mavro

# Default shell
set -g default-command zsh

# Screen addict (replacing Ctrl+b by Ctrl+a)
#set -g prefix C-a
#unbind C-b
#bind C-a send-prefix

# Enable utf8
set -g status-utf8 on
setw -g utf8 on

# Same hack as screen to scroll terminal (xterm ...)
set -g terminal-overrides 'xterm*:smcup@:rmcup@'

# Scrollback buffer n lines
set -g history-limit 100000

# Lock session after delay (in seconds)
set -g lock-after-time 720
# Use vlock to lock session (aptitude install vlock)
set -g lock-command vlock
# To unlock as a user
#vlock -a
# To unlock as root
#vlock -sn

# Highlight active window
set-window-option -g window-status-current-bg red

# Split easier keys (| for horizontal and - for vertical)
bind | split-window -h
bind - split-window -v

# Set window notifications when somethings new happen
setw -g monitor-activity on
set -g visual-activity on
#set -g visual-bell on

# Start window to number to 1 (default 0)
set -g base-index 1

# Automatically set window title
setw -g automatic-rename

# force resize local window
#setw -g aggressive-resize on

# Enable mouse
#set -g mouse-select-pane on
#setw -g mode-mouse on
  

Launch a Program with Tmux at Boot

You may want to launch weechat (IRC client) or other program in tmux when your machine starts. To do this, it’s easy:

  su - deimos -c "tmux new-session -d 'weechat-curses'"
  

Here we’re asking tmux to create a new session via the deimos user.

Resources

Last updated 25 Jan 2013, 07:47 +0200. history