创建新会话
tmux new -s Test
查看会话
tmux list-sessions
连接已有会话
tmux attach -t Test
tmux attach -t Test -r #只读模式
断开会话
Ctrl + b, d
会话中的窗口操作
前缀按键,默认为Ctrl + b
,以下命令,先按前缀键后再执行
命令 | 功能 |
---|---|
c | 创建新窗口 |
, | 重命名当前窗口 |
0-9 | 切换窗口(下面有窗口编号,当前窗口后面有* ) |
( / p | 切换到前一个窗口 |
) / n | 切换到后一个窗口 |
d | 分离当前客户端 |
L | 切换会话 |
i | 显示当前窗口信息 |
% | 垂直分割窗口 |
" | 水平分割窗口 |
方向键 | 切换窗格 |
空格 | 调整窗格排列方式 |
{/} | 交换窗格 |
Ctrl + 方向键 | 调整窗口分割线 |
x | 关闭当前窗格 |
z | 最大化当前窗格(窗口名称后会添加*Z) |
t | 显示时间 |
Tmux插件
Oh My Tmux!
Pretty & versatile tmux configuration made with ❤️ (imho the best tmux configuration that just works)
Github:https://github.com/gpakosz/.tmux
默认没有~/.tmux.conf文件,Oh My Tmux是一套优化好的tmux配置。
- 安装
Requirements:
tmux >= 2.1 running inside Linux, Mac, OpenBSD, Cygwin or WSL (Bash on Ubuntu on Windows)
outside of tmux, $TERM must be set to xterm-256color
To install, run the following from your terminal: (you may want to backup your existing ~/.tmux.conf first)
cd ~
git clone https://github.com/gpakosz/.tmux.git
ln -s -f .tmux/.tmux.conf
cp .tmux/.tmux.conf.local .
tmux-plugin-manager
Github:https://github.com/tmux-plugins/tpm
使用apt安装
apt install tmux-plugin-manager
安装路径为/usr/share/tmux-plugin-manager
使用apt或克隆源码后,编辑~/.tmux.conf
文件,添加以下几行内容:
#List of plugins
set -g @plugin 'tmux-plugins/tpm'
set -g @plugin 'tmux-plugins/tmux-sensible'
#Other examples:
# set -g @plugin 'github_username/plugin_name'
# set -g @plugin 'git@github.com/user/plugin'
# set -g @plugin 'git@bitbucket.com/user/plugin'
#Initialize TMUX plugin manager (添加到.tmux.conf文件最后一行)
run -b 'usr/share/tmux-plugin-manager/tpm'
tmux-logging
Github:https://github.com/tmux-plugins/tmux-logging
- 使用TPM安装 (推荐该方式)
编辑~/.tmux.conf
文件,增加一行:
set -g @plugin '/tmux-plugins/tmux-logging'
然后进入Tmux,按prefix + I
刷新插件,tpm会自动下载该插件。
- 使用:
记录日志
Toggle (start/stop) logging in the current pane.
快捷键:prefix + shift + p
File name format: tmux-#{session_name}-#{window_index}-#{pane_index}-%Y%m%dT%H%M%S.log
File path: $HOME (user home dir)
Example file: ~/tmux-my-session-0-1-20140527T165614.log截屏
Save visible text, in the current pane. Equivalent of a "textual screenshot".
快捷键:prefix + alt + p
日志文件名格式: tmux-screen-capture-#{session_name}-#{window_index}-#{pane_index}-%Y%m%dT%H%M%S.log
文件保存路径: $HOME (user home dir)
NOTE: this functionality depends on the value of history-limit - the number of lines Tmux keeps in the scrollback buffer. Only what Tmux kept will also be saved, to a file.
Useset -g history-limit 50000 in .tmux.conf
, with modern computers it is ok to set this option to a high number.
- 清除pane历史记录
快捷键:prefix + alt + c
修改日志条数
#increase history size
set -g history-limit 10000
搜索、选择、复制
Ctrl-b + [,进入选择模式,可以设置VI的搜索快捷键进行搜索,按空格开始选择,按回车确认选择内容
Ctrl-b + ], 粘贴选择的内容
使用VI搜索快捷键
编辑~/.tmux.conf
,添加一行内容:
# Use vim keybindings in copy mode
setw -g mode-keys vi
复制内容到系统剪贴板
# -- clipboard -----------------------------------------------------------------
# in copy mode, copying selection also copies to the OS clipboard
# - true
# - false (default)
# on macOS, this requires installing reattach-to-user-namespace, see README.md
# on Linux, this requires xsel or xclip
tmux_conf_copy_to_os_clipboard=true
支持鼠标模式
# start with mouse mode enabled
set -g mouse on
Xshell中,开启鼠标模式后,按住Shift点击邮件,调出Xshell的右键菜单。