Tmux 使用筆記

syrchina發表於2016-12-28

命令列

tmux new[-session] -s name -d 新建會話(-d 是否在後臺)
tmux new -s name -n windowname 新建會話及視窗
tmux at[tach] -t session 重新連線(-t 後接會話名稱)
tmux ls 顯示儲存的會話
tmux kill-session -t session 刪除會話

tmux 命令

輸入 tmux 命令的兩種方式

  1. Pre : [command]
  2. 在另一個終端,輸入 tmux [command] -t sessionname
choose-buffer 顯示所有buffer的內容並貼上
list-buffer 顯示所有buffer
save-buffer -a -b N output 將N號buffer的內容輸出(-a 表示新增內容)
show-buffer -b N 顯示N號buffer
set-buffer -b N data 將N號buffer的內容重置
capture-pane 將當前皮膚的內容抓取至0號buffer中
swap-pane -s sp -t tp 交換sp和tp
break-pane 將皮膚變成視窗
join-pane -s Sess:S.p -t TSess:T.p 將Sess會話中S視窗中的p皮膚(比如0:1.1)合併至T視窗中的皮膚
new-window -n name “shell command” 新建視窗並執行命令
move-window -r -s Sess:w -t Sess:w 在會話間移動視窗

快捷鍵繫結

注意 :部分非預設繫結,需結合下節的配置檔案使用。

Pre [/ESCAPE 進入複製模式
Pre [N] ]/p 複製buffer內的內容
Pre = 選擇並貼上buffer
Pre ( 前一個會話
Pre ) 後一個會話
Pre c 新建視窗
Pre , 改變視窗的名字
Pre $ 改變會話的名字
Pre x 前一個視窗
Pre n 後一個視窗
Pre C-h/C-l 前後視窗
Pre [0-9] 選擇視窗
Pre f 搜尋視窗
Pre w 列出所有視窗並選擇
Pre . 移動視窗到新的編號
Pre & 退出視窗
Pre Alt-[1-5] 切換皮膚的佈局
Pre Space 切換皮膚佈局
Pre C-o 順序輪換皮膚
Pre M-o 逆序輪換皮膚
Pre {/} 上/下交換皮膚(swap-pane -U/-D)
Pre o 切換當前皮膚
Pre l/r/u/d 切換當前皮膚
Pre C-l/r/u/d 改變皮膚大小
Pre L/R/U/D 改變皮膚大小
Pre q 顯示皮膚編號並選擇
Pre ! 將皮膚改為視窗
Pre % 豎排新建皮膚
Pre “ 橫排新建皮膚
Pre z 關閉皮膚

參考配置檔案

# setw == set-window-option
# set -s server option
# set -g global option
# bind == bind-key

# add manpage highlight
set -g default-terminal "screen-it"
set -g prefix C-s
# get out of delay time
set -sg escape-time 1
# repeat-time
set -g repeat-time 1000

# let window/pane begin at 1
set -g base-index 1
set -g pane-base-index 1

setw -g mode-keys vi

# status-bar
set -g status-utf8 on
set -g status-left-length 40
set -g status-left "#[fg=black]Session: #S #[fg=blue]#I #[fg=red]#P"
set -g status-right "#[fg=black]%d %b %R"
set -g status-justify centre

# mouse
set -g mode-mouse on
set -g mouse-resize-pane on
set -g mouse-select-pane on
set -g mouse-select-window on


# keybinds
unbind C-b
bind C-s send-prefix

bind r source-file ~/.tmux.conf \; display "Reloaded!"

# windows
bind -r C-h select-window -t :-
bind -r C-l select-window -t :+
bind x last-window

# panes
bind | split-window -h
bind -r h select-pane -L
bind -r j select-pane -D
bind -r k select-pane -U
bind -r l select-pane -R
bind -r H resize-pane -L 5
bind -r J resize-pane -D 5
bind -r K resize-pane -U 5
bind -r L resize-pane -R 5

bind z kill-pane

# copy and paste
bind Escape copy-mode
bind p paste-buffer
bind -t vi-copy 'v' begin-selection
bind -t vi-copy 'y' copy-selection

# toggle log pane
bind P pipe-pane -o "cat >>~/#W.log" \; display "Toggled logging to ~/#W.log"
from: http://mindonmind.github.io/notes/linux/tmux.html