tmux基本操作

会话常用命令

在正常终端模式下,列出当前有哪些tmux会话

tmux ls

新建会话:

直接新建一会话,并进入

tmux

记编号总是不那么容易的,所以一般会在新建会话时,给会话命名,方便记忆,以后也好操作 新建一命名为 abc 的会话

tmux new -s abc

休眠会话

在正常终端模式下,使某个编号的会话强制休眠,编号用的是tmux ls命令时所列出的每一行的最前面的那个编号

tmux detach -t 编号
tmux detach -s 名称

休眠 abc 会话

tmux detach -s abc

恢复会话

连接回以前的某个编号的 tmux 会话,编号用的是 tmux ls 命令时所列出的每一行的最前面的那个编号

tmux attach -t 编号    也可简写成
tmux a -t 编号

连接上 abc 会话

tmux attach -t abc   或者
tmux a -t abc

重命名会话名称

重命名 abc 会话名称为 cba

tmux rename -t abc cba

终止会话

杀死整个 cba 会话

tmux kill-session -t cba

窗口常用命令

假设命令前缀为默认的 : Ctrl+b

{前缀} c 创建新窗口
{前缀} n 选择下一个窗口
{前缀} p 选择前一个窗口
{前缀} l 最近一次活跃窗口之间进行切换
{前缀} 0~9 选择几号窗口
{前缀} , 重命名窗口
{前缀} . 更改窗口的编号,但只能更改成未使用的编号,所以要交换窗口的话,得更改多次进行交换
{前缀} & 关闭窗口
{前缀} w 以菜单方式显示及选择窗口
{前缀} f 在所有窗口中查找内容
{前缀} " 模向分隔面板
{前缀} % 纵向分隔面板
{前缀} o 跳到下一个分隔面板
{前缀} x 关闭面板
{前缀} ; 切换到最后一个使用的面板
{前缀} 上下键 上一个及下一个分隔面板
{前缀} 空格键 切换面板布局 

显示时间

{前缀} t 显示时钟

tmux中的复制和粘贴

在Tmux中通过[进入拷贝模式,按下<space>开始拷贝。

然后用Vim/Emacs快捷键选择文本,按下<Enter>拷贝所选内容。

然后通过]进行粘贴。

上述所有快捷键中,只有 [ 和 ] 需要先按下{前缀}。

我们可以让上述拷贝快捷键符合Vi风格:

bind Escape copy-mode
bind -t vi-copy v begin-selection
bind -t vi-copy y copy-selection
unbind p
bind p pasteb
setw -g mode-keys vi      # Vi风格选择文本

这样,按下<Escape>进入拷贝模式:

v进行选择;

y拷贝所选内容;

p进行粘贴;

tmux配置文件

将以下内容放在 ~/.tmux.conf 文件里面,没有该文件就直接新创建一个。请注意:以下的配置文件,tmux的前缀组合按键仍然是 C-b 。

重载Tmux配置

bind r source-file ~/.tmux.conf ;
display 'Reload ~/.tmux.conf'

配置项目

# 开启window/pane里面的鼠标支持
set-option -g mouse on
# Pane跳转快捷键 bind h select-pane -L bind j select-pane -D bind k select-pane -U bind l select-pane -R # Pane大小调节快捷键 bind -r H resize-pane -L 5 bind -r J resize-pane -D 5 bind -r K resize-pane -U 5 bind -r L resize-pane -R 5 # 新Pane保持原来的目录,而不是跳转到HOME目录 bind % split-window -h -c '#{pane_current_path}' bind '"' split-window -v -c '#{pane_current_path}'


########################## 以上是我常用配置 #############################

# # UI配置 # # 状态栏颜色 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 setw -g window-status-current-fg white setw -g window-status-current-bg red setw -g window-status-current-attr bright # 面板分割栏颜色 set -g pane-border-fg green set -g pane-border-bg black set -g pane-active-border-fg white set -g pane-active-border-bg yellow # TMUX消息提醒 set -g message-fg white set -g message-bg black set -g message-attr bright set -g status-left-length 40 set -g status-left " #[fg=colour233,bg=colour12,bold] #h: #S #[fg=colour233,bg=yellow,bold] #I #[fg=colour233,bg=cyan,bold] #P " set -g status-right ' #[fg=colour233,bg=colour241,bold] %m/%d #[fg=colour233,bg=colour245,bold] %H:%M ' # 消息栏字体使用UTF-8编码 # set -g status-utf8 on # 消息刷新时间为60s set -g status-interval 60 # 窗口列表居中 set -g status-justify centre # 当其它Pane有消息的时候突出显示 setw -g monitor-activity on set -g visual-activity onbind -r K resize-pane -U 5 bind -r L resize-pane -R 5 # 新Pane保持原来的目录,而不是跳转到HOME目录 bind % split-window -h -c '#{pane_current_path}' bind '"' split-window -v -c '#{pane_current_path}' # # UI配置 # # 状态栏颜色 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 setw -g window-status-current-fg white setw -g window-status-current-bg red setw -g window-status-current-attr bright # 面板分割栏颜色 set -g pane-border-fg green set -g pane-border-bg black set -g pane-active-border-fg white set -g pane-active-border-bg yellow #et -g message-fg white set -g message-bg black set -g message-attr bright set -g status-left-length 40 set -g status-left " #[fg=colour233,bg=colour12,bold] #h: #S #[fg=colour233,bg=yellow,bold] #I #[fg=colour233,bg=cyan,bold] #P " set -g status-right ' #[fg=colour233,bg=colour241,bold] %m/%d #[fg=colour233,bg=colour245,bold] %H:%M ' # 消息栏字体使用UTF-8编码 # set -g status-utf8 on # 消息刷新时间为60s set -g status-interval 60 # 窗口列表居中 set -g status-justify centre # 当其它Pane有消息的时候突出显示 setw -g monitor-activity on set -g visual-activity on set -g message-fg white set -g message-bg black set -g message-attr bright set -g status-left-length 40 set -g status-left " #[fg=colour233,bg=colour12,bold] #h: #S #[fg=colour233,bg=yellow,bold] #I #[fg=colour233,bg=cyan,bold] #P " set -g status-right ' #[fg=colour233,bg=colour241,bold] %m/%d #[fg=colour233,bg=colour245,bold] %H:%M '

消息栏字体使用UTF-8编码

set -g status-utf8 on

消息刷新时间为60s

set -g status-interval 60

窗口列表居中

set -g status-justify centre

当其它Pane有消息的时候突出显示

setw -g monitor-activity on


set -g visual-activity on bind Escape copy-mode
bind -t vi-copy v begin-selection
bind -t vi-copy y copy-selection
unbind p
bind p pasteb
setw -g mode-keys vi # Vi风格选择文本

原文地址:https://www.cnblogs.com/defifind/p/10826180.html