Wednesday, May 15, 2013

How to Install and Use tmux on Ubuntu 13.04

Before installing tmux, it's a good idea to update apt to ensure we have the latest packages.
# sudo apt-get update

Then install tmux:
# sudo apt-get install tmux

Run tmux:
# tmux

Run existing tmux:
# tmux a -d

tmux.conf configuration file:
As per dpkg -L tmux which shows you what files the package installed, there is no default tmux.conf included in the package. /etc/tmux.conf is just a location that you may use (only makes sense with multiple users using tmux) that will be evaluated before ~/.tmux.conf. You have to create your own .conf file

# dpkg -L
# ls /usr/share/doc/tmux/examples

# vi ~/.tmux.conf

### Note: key meaning
### C- means ctrl-, so C-x is ctrl-x.
### M- means meta (generally left-alt or escape)-, so M-x is left-alt-x.

### Set the prefix to ^A.
### Note: the default prefix is Ctrl-b.
unbind C-b
set -g prefix ^A
bind a send-prefix

### Set the maximum number of lines held in window history.
set -g history-limit 5000

### terminal 256 colors.
### As the tmux manual suggests: for tmux to work correctly, this must be set to "screen" or a derivative of it.
### Note: modify following line and set it to the terminal supported by your system (run cat /etc/termcap | egrep 'screen-256color|xterm-256color' to verify), and uncomment it.
###set -g default-terminal screen-256color
set -g default-terminal xterm-256color

### Instructs tmux to expect UTF-8 sequences to appear in this window.
setw -g utf8 on

### Instruct tmux to treat top-bit-set characters in the status-left and status-right strings as UTF-8;
set -g status-utf8 on

### date format: hostname weekday month day, hour:minute
set -g status-right '#h %a %b %d, %H:%M'

### Set status line background colour.
set -g status-bg black

### Set status line foreground colour.
set -g status-fg yellow

### Set status line background colour for the currently active window.
setw -g window-status-current-bg magenta

### Set status line foreground colour for the currently active window.
setw -g window-status-current-fg white

### Reload tmux.conf configuration file
### Note: alternative way to reload the configuration file:
### Method 1: Run from command line: tmux source-file ~/.tmux.conf
### Method 2: In any tmux sessions: [prefix Ctrl-b] : source-file /usr/local/etc/tmux.conf
### Method 3: bind the source-file command with a key like following line, then you type: ctrl-b-r
bind r source-file /usr/local/etc/tmux.conf

### [START] vi- and vim-like bindings
### split windows like vim
### vim's definition of a horizontal/vertical split is reversed from tmux's
bind s split-window -v
bind v split-window -h

### move around panes with hjkl, as one would in vim after pressing ctrl-w
bind h select-pane -L
bind j select-pane -D
bind k select-pane -U
bind l select-pane -R

### resize panes like vim
### feel free to change the "5" to however many lines you want to resize by, only
### one at a time can be slow
bind < resize-pane -L 5
bind > resize-pane -R 5
bind - resize-pane -D 5
bind + resize-pane -U 5

### bind : to command-prompt like vim
### this is the default in tmux already
bind : command-prompt

### vi-style controls for copy mode
setw -g mode-keys vi
### [END] vi- and vim-like bindings

Reference:
http://askubuntu.com/questions/192401/where-is-the-default-tmux-conf-file-located

No comments: