Wednesday, May 30, 2012

Tmux 用法


tmux 是噗浪上 @mosky 大大之前推薦的 terminal multiplexer

其實這玩意跟 screen 很像,不過最大差別應該在於 license 不同 (BSD vs GPL),有人不爽用XDDD

他最強大的功能在於 split pane




screen 的概念是一個 screen 底下有多個 window

tmux 則是可以用有多個 window,window 底下又可以有多個 pane, pane 又可以隨時展開成 window









精美圖片來源: http://josephjiang.com/entry.php?id=373 




tmux 還有一個特色功能就是 title 可以設成中文 (貌似是 UTF8)

不過應該沒人會無聊設 title 時還切換輸入法打中文,好像是有點雞肋的功能XDD




漫畫


src: http://pragprog.com/book/bhtmux/tmux




一般 Debian based Linux 可以用 apt-get install tmux 直接安裝








Ctrl-B (前導鍵, 類似 screen 的 Ctrl-A)

不過如果在像是 vim 或是 less 等基於 vi UI 的 pager

Ctrl-B 是 PageUp ,反而操作不便(要多按兩下)

screen 綁的 Ctrl - A 在 vim 裏面是比較不會用到的數字物件遞增的功能,較不會影響我對 vim 的使用

當然 config 寫一寫這些 key binding 都可以改的XDDD






以下常用功能介紹


基於 window
Ctrl-B c          create 創建新 window
Ctrl-B &          關閉目前的 window
Ctrl-B n/p        next/previous 切換到下一個 / 上一個 window
Ctrl-B [N]        切換到 [N] 號 window
Ctrl-B d          detach 目前的 session / shell 下 tmux attach 可以恢復 session
Ctrl-B ?          大絕招,顯示所有 key binding
Ctrl-B ~          tmux message log
Ctrl-B l          兩個 window 間往返
Ctrl-B w          window list
Ctrl-B ,          rename window title

基於 pane
Ctrl-B "          水平 split
Ctrl-B %          垂直 split
Ctrl-B x          關掉目前 pane
Ctrl-B !          把目前的 pane 搬到新的 window 下
Ctrl-B Ctrl       [上下左右] 調整 pane 大小
Ctrl-B Alt        [上下左右] 調整 pane 大小 (一次調五格)
Ctrl-B space      切切看其他 pane 排列方式
Ctrl-B q          顯示 pane 編號 (持續一秒)
Ctrl-B t          在目前的 pane 顯示時間
Ctrl-B o          切換到下一個 pane
Ctrl-B [上下左右]   切換到該方向的 pane
Ctrl-B { 或 }      向前/後移動 pane
Ctrl-B Alt/Ctrl o 逆時針 / 順時針旋轉 pane


不過其實他的 man page 已經很完整了

           C-b         Send the prefix key (C-b) through to the application.
           C-o         Rotate the panes in the current window forwards.
           C-z         Suspend the tmux client.
           !           Break the current pane out of the window.
           "           Split the current pane into two, top and bottom.
           #           List all paste buffers.
           $           Rename the current session.
           %           Split the current pane into two, left and right.
           &           Kill the current window.
           '           Prompt for a window index to select.
           ,           Rename the current window.
           -           Delete the most recently copied buffer of text.
           .           Prompt for an index to move the current window.
           0 to 9      Select windows 0 to 9.
           :           Enter the tmux command prompt.
           ;           Move to the previously active pane.
           =           Choose which buffer to paste interactively from a list.
           ?           List all key bindings.
           D           Choose a client to detach.
           [           Enter copy mode to copy text or view the history.
           ]           Paste the most recently copied buffer of text.
           c           Create a new window.
           d           Detach the current client.
           f           Prompt to search for text in open windows.
           i           Display some information about the current window.
           l           Move to the previously selected window.
           n           Change to the next window.
           o           Select the next pane in the current window.
           p           Change to the previous window.
           q           Briefly display pane indexes.
           r           Force redraw of the attached client.
           s           Select a new session for the attached client interactively.
           L           Switch the attached client back to the last session.
           t           Show the time.
           w           Choose the current window interactively.
           x           Kill the current pane.
           {           Swap the current pane with the previous pane.
           }           Swap the current pane with the next pane.
           ~           Show previous messages from tmux, if any.
           Page Up     Enter copy mode and scroll one page up.
           Up, Down
           Left, Right
                       Change to the pane above, below, to the left, or to the right of the current pane.
           M-1 to M-5  Arrange panes in one of the five preset layouts: even-horizontal, even-vertical, main-horizontal, main-ver‐
                       tical, or tiled.
           M-n         Move to the next window with a bell or activity marker.
           M-o         Rotate the panes in the current window backwards.
           M-p         Move to the previous window with a bell or activity marker.
           C-Up, C-Down
           C-Left, C-Right
                       Resize the current pane in steps of one cell.
           M-Up, M-Down
           M-Left, M-Right
                       Resize the current pane in steps of five cells.

     Key bindings may be changed with the bind-key and unbind-key commands.

2 comments:



  1. unbind C-b
    set -g prefix C-a

    加入 ~/.tmux.conf
    ya~

    ReplyDelete