2018年12月5日 星期三

tmux 使用說明與基礎設定

使用說明

在terminal中,輸入tmux指令,即會進入tmux視窗中。
若要進入256色模式則須輸入tmux -2

可透過快速鍵分割視窗,並將游標焦點切換至各個視窗中,
使用方式為,先按下prefix鍵(預設為Ctrl+b)並放開,再打入功能鍵,以觸發tmux之快速鍵。

進入tmux session
tmux
若要使用256 color mode
則需輸入tmux -2

跳出session
Ctrl+d

進入已開啟之session
tmux a
進入session with256 color mode 
tmux -2 a

水平分割視窗
Ctrl+b "
垂直分割視窗
Ctrl+b %

切換游標所在視窗
切換至上(下左右)方
Ctrl+b 方向鍵上(下左右)

配置當前視窗大小
分割線向上(下左右)移動
Ctrl+b Alt 同時按方向鍵上(下左右)
(可透過更改tmux設定,改為僅需 Alt 同時按方向鍵)

複製-貼上
Ctrl+b [ 進入複製模式
空格 或 v 開始選取,可按方向鍵上(下左右)做選取動作
enter 結束選取,同時跳出複製模式
Ctrl+b ] 貼上

顯示時間
Ctrl+b t


基礎設定

可透過編寫~/.tmux.conf此檔做客製化設定,若在家目錄中沒有該檔,則需要自行新創一個。

範例設定如下:
#tested on 1.8
set -g prefix C-x
unbind C-b

bind | split-window -h
bind - split-window -v
bind -n  M-Up resize-pane -U 5
bind -n  M-Down resize-pane -D 5
bind -n  M-Left resize-pane -L 5
bind -n  M-Right resize-pane -R 5
set -g status-bg "colour0"
set -g status-fg "colour218"

set-option -g pane-border-fg "colour218"
set-option -g pane-active-border-fg "colour218"
set-window-option -g clock-mode-colour "colour218"

範例說明
更換prefix鍵為Ctrl+x,並將原先的設置取消綁定
set -g prefix C-x
unbind C-b

設置分割視窗快速鍵
垂直分割:
bind | split-window -h
水平分割:
bind - split-window -v

設置當前視窗視窗大小之快速鍵,為Alt+方向鍵上下左右
bind -n  M-Up resize-pane -U 5
bind -n  M-Down resize-pane -D 5
bind -n  M-Left resize-pane -L 5
bind -n  M-Right resize-pane -R 5

變更分隔線顏色
set-option -g pane-border-fg "colour218"
set-option -g pane-active-border-fg "colour218"

變更顯示時間之字體顏色
set-window-option -g clock-mode-colour "colour218"