Skip to content

Instantly share code, notes, and snippets.

@dnmfarrell
Last active December 9, 2019 16:50
Show Gist options
  • Save dnmfarrell/f7256324087241c8ed89 to your computer and use it in GitHub Desktop.
Save dnmfarrell/f7256324087241c8ed89 to your computer and use it in GitHub Desktop.

An Introduction to tmux

Overview

  • Terminal multiplexer
  • Multiple terminals
  • Panes & windows
  • Maintains connections
  • Configurable
  • Easy to use!

Setup

  • Install tmux via package manager or download
  • Make ssh "keep alive" for all connections by adding this to ~/.ssh/config:
host *
  ServerAliveInternal 300
  ServerAliveCountMax 2

Session Control (command line)

  • $ tmux begins a new session
  • $ tmux ls lists available sessions
  • $ tmux attach attaches to a running session

The Prefix

Ctrl-b is the prefix combination. Press the Ctrl key AND the letter b at the same time. When inside a tmux session, the prefix is nearly always pressed before the shortcut key to trigger a command.

For example, to display a list of tmux commands, type: Ctrl-b ?

That means press Control and b together, release, then press ?

You can change the prefix, see the config section.

Window Control

  • Ctrl-b c creates a new window
  • Ctrl-b n next window
  • Ctrl-b p prior window
  • Ctrl-b w list windows

Pane Control

  • Ctrl-b " split pane horizontally
  • Ctrl-b % split pane vertically
  • Ctrl-b o next pane
  • Ctrl-b ; prior pane
  • Ctrl-b direction jump to pane
  • Ctrl-b Ctrl-o swap panes
  • Ctrl-b space arrange panes
  • Ctrl-b + direction change pane size
  • Ctrl-b ! pop a pane into a new window

Scrolling and copy/paste

  • Ctrl-b [ enter scroll mode
  • Ctrl-b esc exit scroll mode
  • Ctrl-space begin highlight for copy
  • Alt-w copy highlighted text
  • Ctrl-b ] paste text

Config Options

~/.tmux.conf is a plaintext file used by tmux for local config. If it doesn't exist, create it! This example config file shows some common options:

# set scroll history to 10,000 lines
set-option -g history-limit 10000

# modern encoding and colors
set -g utf8 on
set-window-option -g utf8 on
set -g default-terminal screen-256color

# unbind the prefix and bind it to Ctrl-a like screen
unbind C-b
set -g prefix C-a
bind C-a send-prefix

# use zsh instead of bash
set -g default-command /bin/zsh
set -g default-shell /bin/zsh

To reload your .tmux.conf within a tmux session, type: Ctrl-b : then source-file ~/.tmux.conf.

tmux has a lot of configuration options, here is advanced config example

Learning Resources

License

Licensed under the FreeBSD (two clause) license.

Author

© David Farrell 2015

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