使用Linux的人不管是開發人員、還是運維人員都不可避免的需要使用到終端模擬器(比如,gnome-terminal
)去執行一些命令或者腳本。
tmux可以將終端模擬器方便的切分為不同的小窗口如下圖如示
tmux的官方介紹是
tmux is a terminal multiplexer. It lets you switch easily between several programs in one terminal, detach them (they keep running in the background) and reattach them to a different terminal. And do a lot more. See the tmux(1) manual page and the README.
這里記錄一下常用的快捷鍵, tmux默認使用 Ctrl-b
作為激活快捷鍵的開關, 激活后可以使用下列快捷鍵
% 將當前Panel(有人稱之為窗格)沿縱軸切分
" 將當前Panel沿橫軸切分
空格 重新排序Panel
ALT+上/下/左/右 改變Panel大小
Z 將當前Panel最大化, 在最大化時可以將當前窗口恢復到正常大小
C 創建一個新的TAB (也稱為window)
N 在TAB之間切換
[ 啟動上下滾動同時進入vim狀態
] 退出上下滾動同時進入vim狀態
Pageup/Pagedown 快速翻譯滾動同時進入vim狀態
由於Ctrl-b 需要用到兩個手指,且相距較遠, 通過配置文件我將其對應到了`按鍵(大寫鍵上面一個, 經過長時間的使用, 不影響鍵盤的使用), 以及Ctrl+\ (只需要右手)兩種激活方式
以下是配置方式
vi ~/.tmux.conf
unbind-key C-b set-option -g prefix ` set-option -g prefix2 'C-\' setw -g mode-keys vi set-option -g history-limit 65535 bind -n C-k clear-history bind '"' split-window -c "#{pane_current_path}" bind % split-window -h -c "#{pane_current_path}" bind c new-window -c "#{pane_current_path}"
另外為了避免每次啟動terminal后都要手動運行tmux, 可以在~/.bashrc中增加一行, 這樣就可以在打開終端時默認啟動tmux了
let shell use tmux as default environment
[[ $TERM != "screen" ]] && exec tmux
以便每次打開terminal時, 默認就進入tmux環境