Tmux

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

share session

https://github.com/philsc/docker-tmux-guest
https://brianmckenna.org/blog/guest_tmux

tmux -S /tmp/pair new -s shared

 chmod to allow other users to access it
chmod 777 /tmp/pair

# now the other user can connect with
tmux -S /tmp/pair attach -t shared -r 

tmux -S /tmp/pair kill-session -t shared
rm -rf /tmp/pair

.tmux.conf

# ~/.tmux.conf
#
# https://github.com/tmux-plugins/tmux-resurrect
# https://github.com/ChrisJohnsen/tmux-MacOSX-pasteboard/issues/56
# https://medium.freecodecamp.org/tmux-in-practice-integration-with-system-clipboard-bcd72c62ff7b
#
# -----------------------------------------------------------------------------

#start-server
# alias tm='tmux attach -t my-session || tmux new -s my-session'
# brew install reattach-to-user-namespace

# Global settings
#set -g default-shell $SHELL
#set-option -g default-command "reattach-to-user-namespace -l zsh"
#bind-key -T copy-mode M-w send-keys -X copy-pipe 'reattach-to-user-namespace pbcopy'
#bind-key -T copy-mode Enter send-keys -X copy-pipe 'reattach-to-user-namespace pbcopy'

set-option -g default-shell "${SHELL}"
set-option -g default-command      "reattach-to-user-namespace -l ${SHELL}"

# Copy
bind-key >  save-buffer $HOME/.tmux-buffer \; \
            run 'reattach-to-user-namespace pbcopy < $HOME/.tmux-buffer' \; \
            display-message "Copied to clipboard."

# 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

#set -g mouse on

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

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

# 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

##################################################
## 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

##################################################
# status
##################################################

#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

# window title
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

##################################################
## copy and paste
##################################################
# Toggle mouse on with ^a m
bind m \
  set -g mouse on

# Toggle mouse off with ^a M
bind M \
  set -g mouse off

# 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 mouse 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@'
# Copy tmux paste buffer to CLIPBOARD
#bind-key -n C-y 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"

# List of plugins
set -g @plugin 'tmux-plugins/tpm'
set -g @plugin 'tmux-plugins/tmux-sensible'
set -g @plugin 'tmux-plugins/tmux-resurrect'
set -g @plugin 'tmux-plugins/tmux-continuum'
set -g @plugin 'tmux-plugins/tmux-yank'
set -g @plugin 'tmux-plugins/tmux-sidebar'

set -g @sidebar-tree-command 'tree -C'
set -g @sidebar-tree-position 'left'

set -g @continuum-restore 'on'
set -g @continuum-boot 'on'
set -g @continuum-boot-options 'iterm'
set -g @continuum-save-interval '5'

set -g @resurrect-capture-pane-contents 'on'
set -g @resurrect-save-shell-history 'off'
set -g @resurrect-strategy-vim 'session' # for vim
set -g @resurrect-strategy-nvim 'session' # for neovim
set -g @resurrect-save-bash-history 'off'

# Other examples:
# set -g @plugin 'github_username/plugin_name'
# set -g @plugin 'git@github.com/user/plugin'
# set -g @plugin 'git@bitbucket.com/user/plugin'

# Initialize TMUX plugin manager (keep this line at the very bottom of tmux.conf)
run '~/.tmux/plugins/tpm/tpm'

https://www.sitepoint.com/10-killer-tmux-tips/
http://louiszhai.github.io/2017/09/30/tmux/

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