0.内容
- 安装tmux
- 安装tmux插件管理
- 安装保存会话和剪贴板插件
1.安装tmux
为什么要使用tmux, 可以永久保存会话, 就不用每次都要切换到对应工作目录中.
- Mac下
brew install tmux
- linux, 参考Github地址
git clone https://github.com/tmux/tmux.git
cd tmux
sh autogen.sh
./configure && make
2.安装tmux插件管理
git clone https://github.com/tmux-plugins/tpm ~/.tmux/plugins/tpm
- 新建~/.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 '[email protected]/user/plugin'
# set -g @plugin '[email protected]/user/plugin'
# Initialize TMUX plugin manager (keep this line at the very bottom of tmux.conf)
run -b '~/.tmux/plugins/tpm/tpm'
- 执行安装
tmux
# 然后按 Prefix + I(Prefix 前置键默认是Control + b, I是大写, 先按Prefix再按大写I)
# 等待安装完成
3.安装保存会话与剪贴板插件.
- 在~/.tmux.conf文件中 # List of plugins 行下, 增加
# 保存会话
set -g @plugin 'tmux-plugins/tmux-resurrect'
# tmux下复制粘贴
set -g @plugin 'tmux-plugins/tmux-yank'
- 执行安装
tmux
# 然后按 Prefix + I(Prefix 前置键默认是Control + b, I是大写, 先按Prefix再按大写I)
# 等待安装完成
4.使用保存会话和剪贴板.
- 保存和恢复会话
# 新建指定名字hugo的会话
tmux new -t hugo
# 保存这个会话,Profix + (control+s), 这样就永久保存会话了.
按Profix + C-s
# 恢复会话, 新建tmux, 再按Profix + C-r 即可恢复
tmux
操作Profix + C-r
多个会话也是使用同样的命令
补充tmux命令
# 连接hugo名字的会话
tmux attach -t hugo
# 保持tmux后台运行
Profix+d
# 在.bashrc中起个别名
alias thugo='tmux attach -t hugo'
source ~/.bashrc
- 复制当前和鼠标选中复制
# Profix + y, 这个是复制当前命令行
# 用鼠标选中tmux任意内容再释放, 就可以复制到剪贴板中.
mac用command+v就可以验证