tmux 只是个工具,是比screen 复杂的多的工具。
其包括下面的模块:
server服务器。输入tmux命令时就开启了一个服务器。
session会话。一个服务器可以包含多个会话。
window窗口。一个会话可以包含多个窗口。
pane面板。一个窗口可以包含多个面板。
我自己的感觉是pane 这个东西基本用不上,给我的感觉有点屠龙之术的意思,过度工程化。
1.新建一个session:
-
#tmux ,当前window 用*表示,最后一个working windows用-表示
-
tmux
-
tmux new-session -s work
-
tmux new-session -s play #multiple session
-
tmux rename-session tutorial #rename session.
-
tmux clear-history #will clear history ,window history.
-
tmux list-sessions, tmux list-se #list session
-
tmux attach-session -t 0 ,tmux attach 0 #attach session
-
tmux list-commands #list all commands
-
,, #+逗号,rename 一个window
-
tmux set-option status off #最下面的状态栏会消失
-
tmux set-option status on #显示最下面的状态栏
-
tmux show-options -g |grep key #查看当前的tmux 状态
2.
我也借用getting started with tmux里面用的,tmux 需要先按一个,然后松开,再按下一个键,例如原始的是是Ctrl+b,松开后按?就会显示所有的key binding.
下面是我自己觉得比较查用的key-binding.默认是Ctrl-b,可以自己定义.
-
<Prefix>,c: 意思是按下Prefix,例如Ctrl-a,松开,然后按后面的键
-
<Prefix>,c: create a new window
-
<Prefix>,l: return to last window
-
<Preifx>,n: 到n个windows 去
-
<Preifx>,?: 查看所有的key-bindings, tmux list-keys could do the same.
-
Ctrl+s: 在上一行命令之后运行,在key-bindings中search
-
<Prefix>,w: choose window
-
<Prefix>,p: switch to previous window
-
<prefix>,n: switch to next window
-
<Prefix>,f: find-windows, search for window by string
-
<Prefix>,d: detach session
-
<Prefix>,~: show all the message
-
<Prefix>,s: switch from sessions interactively
3. tmux 的config files, 每个用户自己管理就好,我建了个/root/.tmux.conf.内容如下
-
#set <Prefix> as Ctrl+a
-
set-option -g prefix C-a
-
#unset Ctrl+b
-
unbind C-b
-
-
#set the editors
-
set-option -g mode-keys vi
-
-
#enable mouse modes, 在windows xshell里面使用鼠标更费劲,less is more.
-
#set-window-option -g mouse-mode on
-
#set-option -g mouse-select-window on
-
#set-option -g mouse-select-pane on
-
#set-option -g mouse-resize-pane on
-
-
#set status bar background,text color
-
set-option -g status-bg blue
-
set-option -g status-fg white
-
#set the active window background in the status bar
-
set-window-option -g window-status-current-bg magenta
-
-
#add reload configure
-
#bind-key C-r source-file ~/.tmux.conf
-
-
#bind key F1,F2,F3,F4 to select windows 1,2,3,4
-
bind-key -n F1 select-window -t :1
-
bind-key -n F2 select-window -t :2
-
bind-key -n F3 select-window -t :3
-
bind-key -n F4 select-window -t :4
-
-
#set status bar
-
#set-option -g status-left-length 25
-
#set-option -g status-left "{#(whoami)@#H}"
-
-
#set escape time for vim
-
set-option -s escape-time 0
-
-
#change window history limit
-
set-option -g history-limit 10000
-
-
#set the display-time 2 seconds (2000 ms)
-
set-option -g display-time 2000
-
-
#set the base-index to 1 rather than 0
-
set-option -g base-index 1
-
set-window-option -g pane-base-index 1
-
-
#extend the pane number show time (3000 ms)
-
set-option -g display-panes-time 3000
4. 如何apply 这个config file. 我觉得这个命令比我在config file 里面的Ctrl-r 更直观,Ctrl-r 没有输出,我prefer这种显式的source-file,宁可自己敲命令
-
tmux source-file ~/.tmux.conf
5. tmux 有多种option, 还有多种mode.
-
#3 types of options: server option,session option,window option
-
-g flag apply to global option
-
-s flag apply to server option
-
#session option do not have flag, it is default.
-
-w flag apply to window option
-
-a flag option expects a string to append
-
-u flag unset an option
-
tmux show-options -g
-
tmux show-options -w
-
tmux show-options -s
-
-
#different tmux modes
-
copy mode: <Prefix>,[
-
command mode: <Prefix>,: enter arbitrary tmux commands,not system command.
-
clock mode:<Prefix>,t: shows the current time
-
#Control mode: allow third-party application to interact with tmux through text-only protocol.
-
tmux list-keys -t emacs-copy #list emacs key binding
-
tmux list-keys -t vi-copy #list vi key binding
-
Esc, or q will leave copy mode.
6. 对于pane的管理太过于复杂,我自己根本用不到。
-
#pane management
-
<Prefix>,%: split the window vertically
-
<Prefix>,": split the window horizontally
-
<Prefix>,o: go to the other pane
-
<Prefix>,up arrow : go to up
-
<Prefix>,left arrow: go to left
-
<Prefix>,right arrow: go to right
-
<Prefix>,down arrow: go to down
-
<Prefix>,x: kill pane
-
<Prefix>,z: zoom pane ,again will zoom it back
-
<Prefix>,q, number : show pane number, you can switch to that pane with number enter
-
<Prefix>,Space bar: cycle through pane layouts
-
其实screen 我觉得就够用了,但是越来越多的工具被制造了出来,tmux,byotu.
另外在xshell 里面 ,配置两处地方。
Terminal->keyboard ->Function key Emulation 选择 “Xterm R6"
Terminal->Vt Modes->Initial VT mode 选择 "Origin Mode(DECOM) "
7. windows 输入法里面有个Ctrl-space 来toggle Ime/NonIme ,这个从GUI上无法修改。据说是个bug. 需要修改注册表,解决方案如下
8. reference:
《Getting started with tmux》
http://www.cnblogs.com/congbo/archive/2012/08/30/2649420.html
阅读(1920) | 评论(0) | 转发(0) |