【VSCode】设置关键字高亮的插件、主要通过以下三步实现:
1. 安装highlight-words插件 打开扩展菜单,搜索highlight-words

2. 配置highlight-words插件
Configuration
The following options can be configured
highlightwords.colors: this is an array of light/dark pairs for respective theme types, you can have as few or as many as you like
定义了一个数组用来存放要高亮的颜色,默认有8个颜色
"highlightwords.colors": [
{ "light": "#b3d9ff", "dark": "cyan" },
{ "light": "#e6ffb3", "dark": "pink" },
{ "light": "#b3b3ff", "dark": "lightgreen" },
{ "light": "#ffd9b3", "dark": "magenta" },
{ "light": "#ffb3ff", "dark": "cornflowerblue" },
{ "light": "#b3ffb3", "dark": "orange" },
{ "light": "#ffff80", "dark": "green" },
{ "light": "#d1e0e0", "dark": "red" }
...
]
定义了一个数组用来存放要高亮的颜色,默认有8个颜色定义了一个数组用来存放要高亮的颜色,默认有8个颜色
highlightwords.box: show highlights as a box around the selections if true, set highlight as background color if false
定义了高亮显示的样式, 只要dark为true,就是显示边框
"highlightwords.box": {
"light": false,
"dark": true
},
highlightwords.defaultMode: the initial mode when initialized. 0=default, 1=whole word, 2=ignore case, 3=whole word and ignore case
默认模式,没用过,保持默认值即可;其取值范围如下:·0:表示默认模式·1:全词匹配。可以避免问题:设置a高亮,导致ab的a也高亮·2:忽略大小写·3:全词匹配且忽略大小写
就是给查询规则,建议使用默认模式,子串也会被查询到
"highlightwords.defaultMode": {
"default": 0
}
highlightwords.showSidebar provides a view in the explorer window for searching, changing options and removing highlights. defaults shown below
"highlightwords.showSidebar": {
"default": true
highlightwords.showSidebar:设置为true,则会再资源管理器添加一个HIGHLIGHTS栏来显示已经高亮的单词
高亮的效果:
3. 设置高亮快捷键F8
通过上面的配置后,就可以使某个单词单独高亮了,按Ctrl+Shift+P,输入Highlight Toggle Current,就可以使光标所在位置的单词高亮。但这种方式很麻烦,我们可以设置一个高亮快捷键,这里设置成F8。
设置步骤:
按Ctrl+Shift+P
输入Highlight Toggle Current
点击右边齿轮图标,进入快捷键页面
点击编辑按钮
按F8
按Enter键完成设置; //非常关键,这里需要回车,特别需要注意。

浙公网安备 33010602011771号