Tmux
Table of Contents

copy

- ctrl-a [ to enter copy mode
- g to go to 1st line
- press space to select
- v for vertical selection (optional)
- G to go to last line
- press Enter to copy selection into bufer

- ctrl-a c to create a new window (optional)
- vim /tmp/x.txt (optional)
- i to enter insert mode
- ctrl-a p will show list of buffers

[tmux-copy-mode http://askubuntu.com/questions/350718/problem-regarding-tmux-copy-mode]

- bind-key -t vi-copy : goto-line
- bind-key -t vi-copy Escape clear-selection
- bind-key -t vi-copy q cancel
- bind-key -t vi-copy v rectangle-toggle
- bind-key -t vi-copy / search-forward
- bind-key -t vi-copy ? search-backward
- bind-key -t vi-copy N search-reverse
- bind-key -t vi-copy n search-again

.tmux.conf

# ~/.tmux.conf
#
# Download latest tmux 1.4 from : 
#   http://voxel.dl.sourceforge.net/project/tmux/tmux/tmux-1.4/tmux-1.4.tar.gz   
# URLs to read:
#
#   - instalation http://schamart.blogspot.com/2010/02/dumped-screen-for-tmux.html
#   - man http://wisconsinlinux.org/tmux-manpage-from-cvs/tmux.1.txt
#   
#
# Other sample tmux.conf files
#
#   https://gist.github.com/raw/830346/dfa743c2a0e1d056df8d869ced3321f25b0b0152/tmux.conf
#
# -----------------------------------------------------------------------------

start-server

# Global settings

# Set prefix to ^a (like screen)
# go to start of line will be C-a C-a
set-option -g prefix C-a
unbind-key C-b
bind-key C-a send-prefix

# don't close windows. just deactivate them. use respawn-window to reactivate.
#setw -g remain-on-exit on

# scrollback buffer n lines
set -g history-limit 50000

# start window indexing at one (default = 0)
set -g base-index 1

# instructs tmux to expect UTF-8 sequences
setw -g utf8 on

# listen for activity on all windows
set -g bell-action any

# Set window notifications
setw -g monitor-activity on
set -g visual-activity on

set -g terminal-overrides "*88col*:colors=88,*256col*:colors=256,xterm*:colors=256"

# tell tmux to use 256 colour terminal
set -g default-terminal "screen-256color"

# xterm-style function key sequences
setw -g xterm-keys on

##################################################
# Key bindings 
##################################################
# reload conf
# Reload the .tmux.conf file with Ctrl-r
bind-key l source-file ~/.tmux.conf \; display-message "Configuration reloaded"

# open a man page in new window
bind-key / command-prompt "split-window -h 'exec man %%'"

# quick view of processes
bind-key "~" split-window -h "exec htop"

# log output
bind-key H pipe-pane 'cat >>$HOME/tmux-#W.log' \; display-message 'Started logging to $HOME/tmux-#W.log'
bind-key h pipe-pane \; display-message 'Ended logging to $HOME/tmux-#W.log'

# quit
bind-key \ confirm-before kill-server
bind-key q confirm-before kill-server

# displays
bind-key * list-clients

# redisplay (default key in tmux is 'r')
#bind-key C-l refresh-client
#bind-key l refresh-client
bind-key r refresh-client

# choose window/session
bind-key "'" choose-window
bind-key '"' choose-session

# function keys
bind-key -n F2 choose-session
bind-key -n F3 split-window -v
bind-key -n F4 kill-pane
bind-key -n F5 split-window -h
bind-key -n F6 select-pane -t :.+
bind-key -n F7 detach
bind-key -n F8 kill-window
bind-key -n F9 command-prompt "rename-window %%"
bind-key -n F10 previous-window
bind-key -n F11 next-window
bind-key -n F12 new-window
bind-key -nr C-n new-window

##################################################
## copy and paste
##################################################
# vi-style controls for copy mode
setw -g mode-keys vi

# copying and pasting
bind-key [ copy-mode
bind-key ] paste-buffer -s \015

# enable mouse selection in copy mode
set -g mode-mouse on
set -g mouse-resize-pane on
set -g mouse-select-pane on
set -g mouse-select-window on

# list all paste buffers (default key is '#')
bind-key b list-buffers

# choose buffer to paste interactively (default key was '=')
bind-key p choose-buffer

# delete the most recently copied buffer of text (default key was '-')
bind-key x delete-buffer

# scrolling with terminal scroll bar
set -g terminal-overrides 'xterm*:smcup@:rmcup@'

##################################################

##################################################
## window
##################################################
#unbind %
bind | split-window -v
#unbind '"'
bind _ split-window -h

# navigate windows using hl, and ctrl-hl (no prefix)
bind-key -r h select-window -t :-
#bind-key -r l select-window -t :+
bind-key -nr C-h select-window -t :-
bind-key -nr C-l select-window -t :+

# Ctrl-Left/Right cycles thru windows (no prefix)
bind-key -n "C-Left"  select-window -t :-
bind-key -n "C-Right" select-window -t :+

# Shift-Left/Right cycles thru windows (no prefix)
bind-key -n "S-Left"  select-window -t :-
bind-key -n "S-Right" select-window -t :+

##################################################

##################################################
## pane
##################################################
# navigate panes using jk, and ctrl+jk (no prefix)
bind-key -r j select-pane -t :.-
bind-key -r k select-pane -t :.+
bind-key -nr C-j select-pane -t :.-
bind-key -nr C-k select-pane -t :.+

# Ctrl-Up/Down cyles thru panes (no prefix)
bind-key -n "C-Up"   select-pane -t :.-
bind-key -n "C-Down" select-pane -t :.+

# Cycle to next pane
bind-key -r Tab select-pane -t :.+

# resize pane with arrow keys
# -r: can be repeated without pressing prefix
#     again (500ms after last '-r' action or prefix)
unbind Left
unbind Right
unbind Down
unbind Up
bind -r Left resize-pane -L 2
bind -r Right resize-pane -R 2
bind -r Down resize-pane -D 2
bind -r Up resize-pane -U 2

# swap panes
bind-key -r J swap-pane -D
bind-key -r K swap-pane -U

# window layouts (emacs-like)
#bind-key 1 break-pane
#bind-key 2 select-layout even-vertical
#bind-key 3 select-layout even-horizontal
#bind-key o select-pane -U

##################################################

set -g status-utf8 on
set -g status-justify centre

# amount of time for which status line messages and other indicators
# are displayed. time is in milliseconds.
set -g display-time 2000

#set -g status-bg default
#set -g status-left "#[fg=cyan]:#[fg=blue]: #[fg=red][ #[fg=green]#H #[fg=red]]#[default]"
#set -g status-left-length 20
#set -g status-right-length 25
#set -g status-right "#[fg=red][ #[fg=green]%H:%M #[fg=magenta]%a %m-%d #[fg=red]] #[fg=blue]:#[fg=cyan]:#[default]" 

#setw -g window-status-format '#[fg=blue,bold]#I #T#[default] '
#setw -g window-status-current-format '#[fg=blue,bold,reverse]#I #T#[default] '
#setw -g window-status-alert-fg re

# window title
# enable wm window titles
set-option -g set-titles on

# wm window title string (uses statusbar variables)
set-option -g set-titles-string '#S:#I.#P #W' # window number,program name,active (or not)

# control automatic window renaming
set-window-option -g automatic-rename on # auto name

# default statusbar colors
set -g status-fg black
set -g status-bg green
set -g status-attr default

# default window title colors
setw -g window-status-fg black
setw -g window-status-bg default
setw -g window-status-attr dim

# active window title colors
setw -g window-status-current-fg black
setw -g window-status-current-bg red
#setw -g window-status-current-attr bright
setw -g window-status-current-attr underscore 

# command/message line colors
set -g message-fg white
set -g message-bg black
set -g message-attr bright,blink

# clock
set-window-option -g clock-mode-colour cyan
set-window-option -g clock-mode-style 24

# Linux clipboard support
# move x clipboard into tmux paste buffer
# bind C-p run "tmux set-buffer \"$(xclip -o -selection clipboard)\"; tmux paste-buffer"
# move tmux copy buffer into x clipboard 
# bind C-y run "tmux save-buffer - | xclip -i -selection clipboard"

# Copy tmux paste buffer to CLIPBOARD
bind-key -n C-c run "tmux save-buffer - | xsel --input --clipboard"

# Paste CLIPBOARD to tmux paste buffer and paste tmux paste buffer
bind-key -n C-v run "tmux set-buffer \"$(xsel --output --clipboard)\"; tmux paste-buffer"

# Toggle mouse on with ^a m
bind m \
  set -g mode-mouse on \;\
  set -g mouse-resize-pane on \;\
  set -g mouse-select-pane on \;\
  set -g mouse-select-window on \;\
  display 'Mouse: ON'

# Toggle mouse off with ^a M
bind M \
  set -g mode-mouse off \;\
  set -g mouse-resize-pane off \;\
  set -g mouse-select-pane off \;\
  set -g mouse-select-window off \;\
  display 'Mouse: OFF'

unbind +
bind + \
  new-window -d -n tmux-zoom 'clear && echo TMUX ZOOM && read' \;\
  swap-pane -s tmux-zoom.0 \;\
  select-window -t tmux-zoom

unbind -
bind - \
  last-window \;\
  swap-pane -s tmux-zoom.0 \;\
  kill-window -t tmux-zoom

ref

tmux attach || tmux new

capture-pane; save-buffer buffer.txt

To reload your ~/.tmux.conf without killing your session, you can simply do :

C-b :source-file /absolute/path/to/your/.tmux.conf

https://gist.github.com/raw/830346/dfa743c2a0e1d056df8d869ced3321f25b0b0152/tmux.conf

installation http://schamart.blogspot.com/2010/02/dumped-screen-for-tmux.html

http://drenet.homelinux.net/drenetwiki/index.php/TMux

http://blog.hawkhost.com/2010/07/02/tmux-%E2%80%93-the-terminal-multiplexer-part-2/#rebinding-action-key

https://wiki.archlinux.org/index.php/Tmux
http://media.kbct.de/home/.tmux.conf
http://www.ocf.berkeley.edu/~abhi/2010/12/24/from-gnu-screen-to-tmux.html
http://tofu.org/drupal/node/182

http://code.google.com/p/yjl/source/browse/dotfiles/tmux.conf

http://codehunk.wordpress.com/2010/04/10/tmux-the-latest-addition-to-my-toolset/

cheatsheet : http://www.dayid.org/os/notes/tm.html
man page: http://wisconsinlinux.org/tmux-manpage-from-cvs/tmux.1.txt

copy-paste http://superuser.com/questions/196060/selecting-text-tmux-copy-mode
http://www.wikivs.com/wiki/Screen_vs_tmux

http://www.danrodney.com/mac/

tmux new -s session_name
    creates a new tmux session named session_name
tmux attach -t session_name
    attaches to an existing tmux session named session_name
tmux list-sessions
    lists existing tmux sessions
tmux detach (prefix + d)
    detach the currently attached session 

prefix + " list session
You can switch between sessions using prefix + s, rename them using prefix + $

window:
at default prefix + , is rename window, mine is F9

you can move window between session:
either invoke the console and type out :move-window or type prefix + .
if type from console, then you need to continue type -t session-x:window-index   (note -t stands for target, in fact you can also define source window with parameter -s)
if you use (prefix + .), then you just need to type session-x: window-index
note above session-x is an existing session, window-index is an index number not currently used in the session x. 

you can share a window between two sessions, that means the two sessions will have the same output window.
thus you do not need to jump between sessions. type in tmux console: link-window

panes:
to list panes, type in tmux console: list-panes

you can change layout of existing panes by using prefix + [Meta+1-5] options, letting you select a variety of layouts. 
where Meta is alt key.

Join:  pulling a window into another window as a pane.  You can even yank it from another session using the [session]:[number|pane] syntax with -s and -t to define source and target. 

join-pane [-dhv] [-p percentage|-l size] [-s src-pane] [-t dst-pane]

When you are done, and you want this pane to go back to being another window, you can use break-pane to break the pane back out to being a window.

break-pane [-d] [-t target-pane]

Helpful tmux commands in console:

:list-keys    or prefix + ?
    lists out every bound key and the tmux command it runs
:list-commands
    lists out every tmux command and its arguments
:server-info
    show tmux version and all information in details

https://coderwall.com/p/_g2vpq

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License