Xintong Li

Tools

tmux

Configuration

~/.tmux.conf

Usage

C-x means ctrl+x and M-x means meta+x. [conf] means this is not default shorcut, but defined ~/.tmux.conf.

Basic

The default <prefix> is C-b. In this configuration, the <prefix> is C-a.

<prefix> ?    getting help
<prefix> r    reload configuration [conf]

Managing sessions

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 switch -t <session_name>

switches to an existing session named session_name

tmux list-sessions

lists existing tmux sessions

tmux detach (<prefix> d)

detach the currently attached session

<prefix> ( previous session
<prefix> ) next session
<prefix> L ‘last’ (previously used) session
<prefix> s choose session from a list
<prefix> D detach session from a list

Managing windows

<prefix> c creat a new window
<prefix> <num> switch to window
<prefix> p previous window
<prefix> n next window
<prefix> w choose window from a list
<prefix> ' select the window index
<prefix> , rename the current window
<prefix> & kill the current window
# move selected window to current session
move-window -s <session_name>:<window_index>

Managing panes

<prefix> % split horizontally (left/right)
<prefix> " split vertically (top/bottom)
<prefix> <hjkl> switch to panes around [conf]
<prefix> C-<hjkl> resize the current pane [conf]
<prefix> { move the current pane to the previous position
<prefix> } move the current pane to the next position
<prefix> ! move the current pane into a new window
<prefix> Z toggle pane zoom
<prefix> x kill the current pane
<prefix> M-1 select-layout even-horizontal
<prefix> M-2 select-layout even-vertical
# join current pane to a target window vertically/horizontally
join-pane -[vh] -t <session_name>:<window_index>

Copy & Paste

<perfix> [ enter copy mode
<space> (copy mode) begin selection
v (copy mode) begin selection [conf]
C-v (copy mode) toggle rectangle selection [conf]
y (copy mode) copy selection and stay in copy mode [conf]
<return> copy selection and quit copy mode
<perfix> ] paste

Troubleshooting

Display italic font

  • Mac & iTerm
    set -g default-terminal "xterm-256color"
    set -as terminal-overrides ',xterm*:sitm=\E[3m'
    
  • Linux
    set -g default-terminal "xterm-256color"
    set -as terminal-overrides ',tmux*:sitm=\E[3m'
    

256 color support for vim background in tmux

Add the following into .bashrc (ubuntu) or .bash\_profile (mac).

export TERM=screen-256color

Put the following statement in .tmux.conf.

set -g default-terminal "screen-256color"

To update the configuration, the tmux session must be killed.

tmux list-sessions
tmux kill-session

For putty:

Set Connection -> Data -> Terminal-type string to xterm-256color

Offline installation

https://www.zybuluo.com/mwumli/note/149542

Tmux borders displayed as x q instead of lines

Add the following in .bashrc

alias tmux='tmux -u'