linux终端分屏显示tmux,screen和tmux分屏

LINUX下有两个比较常用的终端工具:screen和tmux,两者都是支持分屏操作的。不过screen只支持上下分屏,而tmux支持上下左右分屏。这里记录下两者分屏的操作方法。

一、screen分屏

1,输入命令screen使用工具

2,上下分屏:ctrl + a 再按shift + s

3,切换屏幕:ctrl + a 再按tab键

4,新建一个终端:ctrl + a 再按c

5,关闭一个终端:ctrl + a 再按x (或直接按exit退出)

二、tmux分屏

1,输入命令tmux使用工具

2,上下分屏:ctrl + b 再按 "

3,左右分屏:ctrl + b 再按 %

4,切换屏幕:ctrl + b 再按o

5,关闭一个终端:ctrl + b 再按x

6,上下分屏与左右分屏切换: ctrl + b 再按空格键

以下都是在默认没有修改绑定键的情况下的默认值,如果修改了绑定键,还需要根据具体的绑定键的情况再定。这里也推荐一个tmux的配置

set -g prefix ^a

unbind ^b

bind a send-prefix

setw -g mode-keys vi

set -g base-index 1

#水平或垂直分割窗口

unbind '"'

bind - splitw -v -c "#{pane_current_path}" # 分割成上下两个窗口

unbind %

bind | splitw -h -c "#{pane_current_path}" # 分割成左右两个窗口'"'

bind c new-window -c "#{pane_current_path}"

#选择分割的窗格

bind k selectp -U # 选择上窗格

bind j selectp -D # 选择下窗格

bind h selectp -L # 选择左窗格

bind l selectp -R # 选择右窗格

#重新调整窗格的大小

bind ^k resizep -U 10 # 跟选择窗格的设置相同,只是多加 Ctrl(Ctrl-k)

bind ^j resizep -D 10 # 同上

bind ^h resizep -L 10 # ...

bind ^l resizep -R 10 # ...

#交换两个窗格

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

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

# 状态栏设置

# status bar with load and time

set -g status-bg blue

set -g status-fg '#bbbbbb'

set -g status-left-fg green

set -g status-left-bg blue

set -g status-right-fg green

set -g status-right-bg blue

set -g status-left-length 90

set -g status-right-length 90

set -g status-left '[#(whoami)]'

set -g status-right '[#(date +" %m-%d %H:%M ")]'

#set -g status-justify "centre"

set -g window-status-format '#I #W'

set -g window-status-current-format ' #I #W '

setw -g window-status-current-bg blue

setw -g window-status-current-fg green

set -g default-terminal "screen-256color"

将文件存放为~/.tmux.conf,即可使用。配置使用了ctrl+a作为启用键,其功能键作用如下:

水平分割窗格ctrl+-就是control键加0键后面横线键,不需要shift

垂直分割窗格ctrl+|就是control键加回车键上面竖线键,需要shift

选择分割窗格和vim键的上下左右相同hjkl分别对应左、下、上和右

多个窗口时,调整大小的功能键为:

向左 ctrl+h

向右 ctrl+l

向上 ctrl+k

向下 ctrl+j

窗格位置切换的功能键为:

ctrl+u与上窗格交换

ctrl+d与下窗格交换

ctrl+space空格键可以把多个窗格大小统一调整到等宽或者等高。

这里还有一个自动切分窗格的命令:

cmd=$(which tmux) # tmux path

if [ -z $cmd ]; then

echo "You need to install tmux."

exit 1

fi

$cmd has -t $session 2> /dev/null

if [ $? != 0 ]; then

$cmd new -d -n base-act -s $session "zsh"

$cmd splitw -v -t $session

$cmd splitw -h -t $session

$cmd select-layout -t $session tiled

$cmd send-keys -t $session:1.0 '执行的命令' C-m

$cmd send-keys -t $session:1.1 '执行的命令' C-m

$cmd send-keys -t $session:1.2 '执行的命令' C-m

$cmd send-keys -t $session:1.3 '执行的命令' C-m

$cmd set-window-option synchronize-panes on

#$cmd neww -n vim -t $session "zsh"

#$cmd selectw -t $session:5

fi

$cmd att -t $session

exit 0

使用synchronize-panes on脚本自动分割4个窗格出来。这里默认使用的zsh,如果使用的bash shell,也可以将上面的zsh换成bash。

  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值