tmux配置文件和插件

配置文件(~/.tmux.conf)

使用tmux source .tmux.conf使命令生效
打开鼠标后使用shift键选中文字,再按Shift-Ctrl-c复制

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# 基础设置
#设置默认终端模式为 256color
set -g default-terminal "screen-256color"
set -g display-time 3000
set -g escape-time 0
set -g history-limit 65535
set -g base-index 1
set -g pane-base-index 1
# 前缀绑定 (Ctrl+a)
#set -g prefix ^a
#unbind ^b
#bind a send-prefix
# 分割窗口
#unbind '"'
#bind - splitw -v
#unbind %
#bind | splitw -h
# 选中窗口
#bind-key k select-pane -U
#bind-key j select-pane -D
#bind-key h select-pane -L
#bind-key l select-pane -R
# copy-mode 将快捷键设置为 vi 模式
#setw -g mode-keys vi
# 启用鼠标(Tmux v2.1)
set -g mouse on
# 更新配置文件
bind r source-file ~/.tmux.conf \; display "已更新"
#<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
# Tmux Plugin Manager(Tmux v2.1)
# Tmux Resurrect
set -g @plugin 'tmux-plugins/tmux-resurrect'
# 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 (keep this line at the very bottom of tmux.conf)
run '~/.tmux/plugins/tpm/tpm'
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

插件

TPM的安装
跟我们现在常用的很多软件类似,Tmux也支持插件系统,可以通过安装插件扩展出许多功能,让Tmux变得更加强大。在Tmux中,这款插件管理器叫做 TPM - Tmux Plugin Manager。

TPM的安装也比较简单:

1
$ git clone https://github.com/tmux-plugins/tpm ~/.tmux/plugins/tpm

然后,修改Tmux配置文件,让其在启动时加载TPM

1
2
3
4
5
6
7
8
9
10
11
# List olugins
# # Supports `github_username/repo` or full git repo URLs
set -g @plugin 'tmux-plugins/tpm'
set -g @plugin 'tmux-plugins/tmux-resurrect'
set -g @plugin 'tmux-plugins/tmux-sensible'
set -g @plugin 'tmux-plugins/tmux-urlview'
set -g @plugin 'tmux-plugins/tmux-open'
set -g @plugin 'tmux-plugins/tmux-yank'
set -g @plugin 'tmux-plugins/tmux-battery'
set -g @plugin 'tmux-plugins/tmux-cpu'

TPM主要提供插件的安装,更新和移除等管理功能:

1
2
3
<prefix> I 安装插件,并更新Tmux
<prefix> U 更新所有已安装插件
<prefix> Alt U 移除所有插件列表中不存在的插件

常用插件推荐
有了TPM,我们就能够安装和使用各种插件了,这里介绍几款我比较常用的插件:

Tmux Resurrect 一个非常好用的保存当前Tmux窗口和Panel布局的插件。它可以帮助你持久化当前Tmux中所有的窗口和Panel布局。如果你对窗口进行了分割并且精心调整过,在退出Tmux之前可以使用快捷键对布局进行持久化。下一次启动Tmux的时候,也能非常方便的用快捷键恢复上次的窗口布局,真是非常方便。
插件地址:https://github.com/tmux-plugins/tmux-resurrect

将插件添加到TPM插件列表中.tmux.conf:

1
set -g @plugin 'tmux-plugins/tmux-resurrect'

点击prefix + I获取插件并获取它。您现在应该可以使用该插件。

1
2
prefix + Ctrl-s - 保存
prefix + Ctrl-r - 恢复

Tmux urlview 在终端界面中自动搜寻所有的URL链接地址,合并为一个可以选择的列表,然后选中直接在浏览器中打开URL。省去了用鼠标复制URL,再打开浏览器粘贴的繁琐操作,非常高效,值得推荐!
插件地址:https://github.com/tmux-plugins/tmux-urlview

Tmux open 使用系统中默认文件类型对应的程序,快速打开在终端中选中的文件名。这个也非常高效,值得推荐! 插件地址:https://github.com/tmux-plugins/tmux-open

参考:
https://xiaozhou.net/learn-the-command-line-tmux-2018-04-27.html