Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1742953
  • 博文数量: 297
  • 博客积分: 285
  • 博客等级: 二等列兵
  • 技术积分: 3006
  • 用 户 组: 普通用户
  • 注册时间: 2010-03-06 22:04
个人简介

Linuxer, ex IBMer. GNU https://hmchzb19.github.io/

文章分类

全部博文(297)

文章存档

2020年(11)

2019年(15)

2018年(43)

2017年(79)

2016年(79)

2015年(58)

2014年(1)

2013年(8)

2012年(3)

分类: 系统运维

2016-08-17 10:50:38

tmux 只是个工具,是比screen 复杂的多的工具。
其包括下面的模块:
server服务器。输入tmux命令时就开启了一个服务器。
session会话。一个服务器可以包含多个会话。
window窗口。一个会话可以包含多个窗口。
pane面板。一个窗口可以包含多个面板。

我自己的感觉是pane 这个东西基本用不上,给我的感觉有点屠龙之术的意思,过度工程化。
1.新建一个session:

点击(此处)折叠或打开

  1. #tmux ,当前window 用*表示,最后一个working windows用-表示
  2. tmux
  3. tmux new-session -s work
  4. tmux new-session -s play      #multiple session
  5. tmux rename-session tutorial  #rename session.
  6. tmux clear-history #will clear history ,window history.
  7. tmux list-sessions, tmux list-se #list session 
  8. tmux attach-session -t 0 ,tmux attach 0 #attach session 
  9. tmux list-commands #list all commands 
  10. ,, #+逗号,rename 一个window 
  11. tmux set-option status off #最下面的状态栏会消失
  12. tmux set-option status on #显示最下面的状态栏
  13. tmux show-options -g |grep key #查看当前的tmux 状态
2. 我也借用getting started with tmux里面用的,tmux 需要先按一个,然后松开,再按下一个键,例如原始的是是Ctrl+b,松开后按?就会显示所有的key binding.
下面是我自己觉得比较查用的key-binding.默认是Ctrl-b,可以自己定义.

点击(此处)折叠或打开

  1. <Prefix>,c:  意思是按下Prefix,例如Ctrl-a,松开,然后按后面的键
  2. <Prefix>,c:  create a new window
  3. <Prefix>,l:  return to last window
  4. <Preifx>,n:  到n个windows 去
  5. <Preifx>,?: 查看所有的key-bindings, tmux list-keys could do the same.
  6. Ctrl+s:     在上一行命令之后运行在key-bindings中search
  7. <Prefix>,w:  choose window
  8. <Prefix>,p:  switch to previous window
  9. <prefix>,n:  switch to next window
  10. <Prefix>,f:  find-windows, search for window by string
  11. <Prefix>,d:  detach session
  12. <Prefix>,~:  show all the message
  13. <Prefix>,s:  switch from sessions interactively
3. tmux 的config files, 每个用户自己管理就好,我建了个/root/.tmux.conf.内容如下

点击(此处)折叠或打开

  1. #set <Prefix> as Ctrl+a
  2. set-option -g prefix C-a
  3. #unset Ctrl+b
  4. unbind C-b

  5. #set the editors
  6. set-option -g mode-keys vi

  7. #enable mouse modes, 在windows xshell里面使用鼠标更费劲,less is more.
  8. #set-window-option -g mouse-mode on
  9. #set-option -g mouse-select-window on
  10. #set-option -g mouse-select-pane on
  11. #set-option -g mouse-resize-pane on

  12. #set status bar background,text color
  13. set-option -g status-bg blue
  14. set-option -g status-fg white
  15. #set the active window background in the status bar
  16. set-window-option -g window-status-current-bg magenta

  17. #add reload configure
  18. #bind-key C-r source-file ~/.tmux.conf

  19. #bind key F1,F2,F3,F4 to select windows 1,2,3,4
  20. bind-key -n F1 select-window -t :1
  21. bind-key -n F2 select-window -t :2
  22. bind-key -n F3 select-window -t :3
  23. bind-key -n F4 select-window -t :4

  24. #set status bar
  25. #set-option -g status-left-length 25
  26. #set-option -g status-left "{#(whoami)@#H}"

  27. #set escape time for vim
  28. set-option -s escape-time 0

  29. #change window history limit
  30. set-option -g history-limit 10000

  31. #set the display-time 2 seconds (2000 ms)
  32. set-option -g display-time 2000

  33. #set the base-index to 1 rather than 0
  34. set-option -g base-index 1
  35. set-window-option -g pane-base-index 1

  36. #extend the pane number show time (3000 ms)
  37. set-option -g display-panes-time 3000

4. 如何apply 这个config file. 我觉得这个命令比我在config file 里面的Ctrl-r 更直观,Ctrl-r 没有输出,我prefer这种显式的source-file,宁可自己敲命令

点击(此处)折叠或打开

  1. tmux source-file ~/.tmux.conf

5.  tmux 有多种option, 还有多种mode.

点击(此处)折叠或打开

  1. #3 types of options: server option,session option,window option
  2. -g flag apply to global option
  3. -s flag apply to server option
  4. #session option do not have flag, it is default.
  5. -w flag apply to window option
  6. -a flag option expects a string to append
  7. -u flag unset an option
  8. tmux show-options -g
  9. tmux show-options -w
  10. tmux show-options -s

  11. #different tmux modes
  12. copy mode: <Prefix>,[
  13. command mode: <Prefix>,:  enter arbitrary tmux commands,not system command.
  14. clock mode:<Prefix>,t:    shows the current time
  15. #Control mode:             allow third-party application to interact with tmux through text-only protocol.
  16. tmux list-keys -t emacs-copy        #list emacs key binding
  17. tmux list-keys -t vi-copy            #list vi key binding
  18. Esc, or q will leave copy mode.

6. 对于pane的管理太过于复杂,我自己根本用不到。

点击(此处)折叠或打开

  1. #pane management
  2. <Prefix>,%:  split the window vertically 
  3. <Prefix>,":  split the window horizontally
  4. <Prefix>,o:  go to the other pane 
  5. <Prefix>,up arrow :   go to up 
  6. <Prefix>,left arrow:  go to left 
  7. <Prefix>,right arrow: go to right 
  8. <Prefix>,down arrow:  go to down 
  9. <Prefix>,x:  kill pane
  10. <Prefix>,z:  zoom pane ,again will zoom it back 
  11. <Prefix>,q, number :  show pane number, you can switch to that pane with number enter 
  12. <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
阅读(1825) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~