tmux学习笔记

tmux号称screen的替代品,来看看为什么这么说:
[list]
[*]支持多个window之间的粘贴/复制,可以选择粘贴缓冲区,而这screen不支持。
[*]分屏操作完胜。screen只支持简陋的上下分屏,分屏后还需要ctrl+a+c才能创建一个新的终端。screen直接创建一个终端,且支持屏幕之间的切换/relocate/重定义大小,以及提供了一些预置的layout
[*]tmux默认自带status bar,screen还需手动配置
[*]tmux的配置比screen简单
[*]vi和emac模式绑定
[/list]


启动tmux:
tmux ls: list tmux session
tmux attach: attach a tmux session

tmux启动参数:
[list]
[*]-c: shell-command, 比如 tmux -c vim
[*]-f file: 指定配置文件,默认~/.tmux.conf,或者/etc/tmux.conf
[*]-L socket-name: 制定tmux session的名字
[*]-u: 支持utf-8
[*]-V: version
[/list]

tmux的一些概念:

A session is a single collection of pseudo terminals under the management of tmux. Each session has one or more
windows linked to it. A window occupies the entire screen and may be split into rectangular panes, each of
which is a separate pseudo terminal (the pty(4) manual page documents the technical details of pseudo termi‐
nals). Any number of tmux instances may connect to the same session, and any number of windows may be present
in the same session. Once all sessions are killed, tmux exits.


session: 会话,一个服务器可以包含多个session
window: 窗口,一个session可以包含多个window
pane: 面板,一个window可以包含多个pane

tmux 配置:
tmux默认的bind-key是ctrl + b,可以修改为习惯的ctrl+a:
set -g prefix ^a
unbind ^b
bind a send-prefix

设置之后,ctrl+a+a可以在terminal中将光标一到行首



set-option -g display-time 4000
set-option -g status-keys vi
set-window-option -g mode-keys vi

# set default bind-key to ctrl + a
set-option -g prefix C-a
unbind-key C-b
bind-key C-a send-prefix

# unbind '"'
bind - splitw -v # 分割成上下两个窗口
# unbind %
bind | splitw -h # 分割成左右两个窗口

bind k selectp -U # 选择上窗格
bind j selectp -D # 选择下窗格
bind h selectp -L # 选择左窗格
bind l selectp -R # 选择右窗格

bind-key J resize-pane -D 10
bind-key K resize-pane -U 10
bind-key H resize-pane -L 10
bind-key L resize-pane -R 10


bind ^u swapp -U # 与上窗格交换 Ctrl-u
bind ^d swapp -D # 与下窗格交换 Ctrl-d


bind m command-prompt "splitw -h 'exec man %%'" # m: 在新的panel打开man


#定制状态行
#状态行左边默认就很好了,我对右边定制了一下,显示 uptime 和 loadavg:

#set -g status-right "#[fg=green]#(uptime.pl)#[default] • #[fg=green]#(cut -d ' ' -f 1-3 /proc/loadavg)#[default]"

# 下面两行设置状态行的背景和前景色:
set -g status-bg black
set -g status-fg yellow

#默认启动应用
#当 tmux 启动时,可以默认启动一些应用:
#new -s work # 新建名为 work 的会话,并启动 mutt
#neww rtorrent # 启动 rtorrent
#neww vim # 启动 vim
#neww sh
#selectw -t 1 # 默认选择标号为1的窗口



其他一些操作:

[list]
[*] ctrl-b + ,: 更改window的名字
[*] ctrl-b + o: 切换当前window中的panel
[*] ctrl-b + w: 列出所有window并选择
[*] ctrl-b + |: 分屏,两列
[*] ctrl-b + -: 分屏,两行
[*] ctrl-b + m: 输入命令,回车,新开一个panel查看其man手册
[*] ctrl-b + ctrl + u: 按住ctrl同时按u,对换上下两个panel的位置
[*] ctrl-b + ctrl - d: 同上,对换上下两个panel的位置
[*] ctrl-b + { j, k, l, ;}: 切换panel
[*] ctrl-b + J: 当前panel往下增加区域
[*] ctrl-b + K: 当前panel往上增加区域
[*] ctrl-b + H: 往左
[*] ctrl-b + L: 往右
[/list]

以后呢,就愉快的用tmux了,暂时不用screen了~
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值