Tmux 终端复用器美化(2021/11/20)

Tmux 终端复用器美化(2021/11/20)

1. 简介

参考《Tmux 基本使用》

2. 配置

2.1 修改前缀键

Tmux 拥有大量的快捷键,所有的快捷键都需要通过前缀键唤起,默认前缀键为 Ctrl + b,两键相隔较远使用起来不方便,笔者喜欢修改为 Ctrl + x,修改方法如下:

# 编辑 tmux 的用户配置文件,路径为 ~/.tmux.conf,如果没有手动创建
$ vim ~/.tmux.conf
# 加入以下内容
set-option -g prefix2 C-x

注:该操作只是添加了第二个前缀键,并不会影响原前缀键。

2.2 开启鼠标支持

Tmux 支持分屏操作,在各窗格之间切换焦点及更改窗格大小时默认通过前缀键加方向键来实现,在窗格较多时并不方便,故笔者喜欢开启鼠标支持(不会影响键盘操作),开启方法如下:

# 编辑 tmux 的用户配置文件,路径为 ~/.tmux.conf,如果没有手动创建
$ vim ~/.tmux.conf
# 加入以下内容
set-option -g mouse on

2.3 修改复制模式快捷键风格

在 Tmux 中操作文本自然离不开复制模式,通过使用复制模式的过程如下:

  1. 按下 prefix + [ 进入复制模式;
  2. 按下 Space 开始选择文本,移动光标选择复制区域;
  3. 按下 Enter 复制选中文本并退出复制模式;
  4. 按下 prefix + ] 粘贴文本;

Tmux 中复制模式默认的快捷键风格为emacs,笔者更加熟悉vim,故改为vim快捷键风格,修改方法如下:

# 查看 tmux 复制模式快捷键风格
$ tmux show-window-options -g mode-keys

# 编辑 tmux 配置文件,设置为 vi 风格
$ vim .tmux.conf
# 加入以下内容,可以设置为 vi 或 emacs
set-window-option -g mode-keys vi

更多配置参考Tmux使用手册 | louis blog (louiszhai.github.io)

3. 插件

3.1 tpm(Tmux Plugin Manager)

3.1.1 介绍

tpm 是一个 Tmux 插件管理工具,用于安装和管理 Tmux 插件,使插件安装变得更加简单。

3.1.2 安装
# 通过 git 拉取 tpm,如果遇到网络可以通过 https://hub.fastgit.org 镜像下载
# git clone https://hub.fastgit.org/tmux-plugins/tpm ~/.tmux/plugins/tpm
$ git clone https://github.com/tmux-plugins/tpm ~/.tmux/plugins/tpm

注:tpm 使用要求 Tmux 版本等于 1.9。

3.1.3 配置

tpm 配置文件与 Tmux 相同,路径为~/tmux.conf(或$XDG_CONFIG_HOME/tmux/tmux.conf),编辑该文件添加 tpm 相关的配置,具体操作如下:

# 修改 tmux 配置
$ vim ~/.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 'github_username/plugin_name#branch'
# set -g @plugin 'git@github.com:user/plugin'
# set -g @plugin 'git@bitbucket.com:user/plugin'

# Initialize TMUX plugin manager (keep this line at the very bottom of tmux.conf)
run '~/.tmux/plugins/tpm/tpm'

# 重载 tmux 配置
$ tmux source ~/.tmux.conf
3.1.4 插件安装
  1. 按照 set -g @plugin '...' 的格式将新插件添加到 .tmux.conf 文件;
  2. 按下 prefix + I 下载安装插件;
3.1.5 插件卸载
  1. 将插件从 .tmux.conf 文件移除;
  2. 按下 prefix + Alt + u 卸载插件;
3.1.6 快捷键
  • prefix + I:安装插件并刷新 Tmux 环境。
  • prefix + u:更新插件。
  • prefix + Alt + u:卸载插件。

3.2 插件推荐

此处不再详细介绍每个插件的功能与作用,所有插件均可在 Github 搜索下载。

set -g @plugin 'arcticicestudio/nord-tmux'
# set -g @plugin 'tmux-plugins/tmux-battery'
# set -g @plugin 'tmux-plugins/tmux-cpu'
# set -g @plugin 'tmux-plugins/tmux-prefix-highlight'
# set -g @plugin 'tmux-plugins/tmux-online-status'
# set -g @plugin 'tmux-plugins/tmux-net-speed'
# set -g @plugin 'tmux-plugins/tmux-sidebar'
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值