tmux使用(程序员适用)

[b][size=medium]tmux基本使用[/size][/b]
tmux是一个优秀的终端复用软件,即使[color=blue]非正常掉线,也能保证当前的任务运行[/color],这一点对于远程SSH访问特别有用,网络不好的情况下仍然能保证工作现场不丢失!
tmux完全使用键盘控制窗口,实现窗口的切换,像是Chrome的方式管理shell,使用起来很方便,byubo也有同样的功能。[img]http://tmux.sourceforge.net/small-tmux3.png[/img]
tmux命令都具有一个前缀命令[b](PREFIX[/b]),默认的是CTRL+b,可以自己修改,改为CTRL+a。
在~/.tmux.conf中加入如下行,没有~/.tmux.conf文件自己建立一个即可。
[color=red]set -g prefix C-a
unbind C-b[/color]
此时并没有生效,重启tmux或者在命令模式(按[b]PREFIX :[/b] )输入
[color=red]source-file ~/.tmux.conf[/color]
任何命令前都需要CTRL+a,然后再按其他的键发出具体的操作命令,更多命令请看[url="http://www.openbsd.org/cgi-bin/man.cgi?query=tmux&sektion=1"]tmux参考手册[/url]

[b]1 建立命名会话[/b]
# tmux new -s session
进入tmux。
[b]PREFIX c[/b] 创建新的窗口
[b]PREFIX d[/b] 退出tmux窗口,tmux仍在后台运行,可以通过tmux attach进入到指定的会话

# tmux new -s session -d [color=blue]#在后台建立会话[/color]
# tmux ls [color=blue]#列出会话[/color]
# tmux attach -t session [color=blue]#进入某个会话[/color]

[b][size=medium]2 复制模式copy-mode[/size][/b]
a.[b]PREFIX [[/b] 进入复制模式
b.按 [b]space[/b] 开始复制,移动光标选择复制区域
c.按 [b]Enter[/b] 复制并退出copy-mode。
d.将光标移动到指定位置,按 [b]PREIFX ][/b] 粘贴
如果不在配置文件中进行如下配置,在VIM中复制模式无法完成操作
在[b]~/.tmux.conf[/b]中加入如下行
[color=red]setw -g mode-keys vi[/color]

[b][size=medium]3 Remaping key[/size][/b]
讲[b]Caps Lock[/b]键映射为[b]Ctrl[/b],更改键映射后反而有点不习惯,就用默认的键盘控制也很方便,习惯就好。
windows环境下载安装AUTOHOTKEY,修改[url="http://www.cs.umb.edu/~wimiller/stuff/caps2ctrl.ahk"]AutoHotKey.ahk[/url]文件为
;;; Default script settings
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
;;; Remap CapsLock to Control. Move CapsLock to Right Control.
CapsLock::Control
RControl::CapsLock
运行AutoHotKey,如已运行可以reload。更多修改CapsLock到CTRL的方法,请参考文章[url="http://www.emacswiki.org/emacs/MovingTheCtrlKey#toc7"]MovingTheCtrlKey[/url]

[b]4 配置[/b]
#设置PREFIX为Ctrl-a
set -g prefix C-a
#解除Ctrl-b与PREFIX的对应关系
unbind C-b
#copy-mode将快捷键设置为vi模式
setw -g mode-keys vi
#将r键设置为加载配置文件,并显示"reloaded!"信息
bind r source-file ~/.tmux.conf \; display "Reloaded!"
#设置终端颜色为256色
set -g default-terminal "screen-256color"
#开启status-bar uft-8支持
set -g status-utf8 on
#设置pan前景色
set -g pane-border-fg green
#设置pane背景色
set -g pane-border-bg black
#设置活跃pane前景色
set -g pane-active-border-fg white
#设置活跃pane背景色
set -g pane-active-border-bg yellow
#设置消息前景色
set -g message-fg white
#设置消息背景色
set -g message-bg black
#设置消息高亮显示
set -g message-attr bright
#设置status-bar颜色
set -g status-fg white
set -g status-bg black
#设置窗口列表颜色
setw -g window-status-fg cyan
setw -g window-status-bg default
setw -g window-status-attr dim
#设置当前窗口在status bar中的颜色
setw -g window-status-current-fg white
setw -g window-status-current-bg red
setw -g window-status-current-attr bright
#设置status bar格式
set -g status-left-length 40
set -g status-left "#[fg=green]Session: #S #[fg=yellow]#I #[fg=cyan]#P"
set -g status-right "#[fg=cyan]%d %b %R"
set -g status-interval 60
set -g status-justify centre
#开启window事件提示
setw -g monitor-activity on
set -g visual-activity on


[b]5 滚屏[/b]
滚屏要进入copy-mode,即PREFIX+[,然后就可以用上下键来滚动屏幕,配置了vi快捷键模式,就可以像操作vi一样来滚动屏幕,非常的方便。
退出直接按‘q’键即可。

更多工具参考[url="http://kkovacs.eu/cool-but-obscure-unix-tools"]Kristóf Kovács的博客[/url]及[url="http://coolshell.cn/articles/7829.html"]coolshell的博客[/url]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值