VS Code 磨刀日记 #1: 配置项

3,982 阅读2分钟

记录在使用 VS Code 过程中,觉得对自己有帮助的一些配置项,会一直更新,也欢迎大家分享一些有用的配置项到评论区。

每个配置项标题括号内的即为该配置项的 id,在 VS Code 设置页面的搜索框里粘贴 id 即可跳转到配置项:

preference-search

Fast Scroll (editor.fastScrollSensitivity)

在速览大文件的时候,除了可以在 minimap 中进行拖动,还可以按住 alt 键进行快速滚动,滚动的步长可以通过 editor.fastScrollSensitivity 配置项进行配置。

fast-scroll

Linked Editing (editor.linkedEditing)

众所周知,在用 VS Code 编辑 HTML 文件的时候,HTML 的开始标签和配对的结束标签并不会默认关联,也就是说编辑了开始标签,结束标签并不会同步更新:

linked-editing__default

通过 Rename Symbol 命令 (快捷键 F2) 可以实现 HTML 的关联编辑:

linked-editing__rename-symbol

不错,这样已经实现了关联编辑的功能,但是每次需要执行 Rename Symbol 操作,如果能够在编辑开始标签的时候,自动替换与之配对的结束标签就好了,所以就有了 formulahendry.auto-rename-tag 插件,安装后,在编辑 HTML 或者 XML 文件的时候,就能够自动关联编辑标签。

linked-editing__plugin

但其实在 1.44 版本之后,VS Code 就内置了这个功能,将 editor.linkedEditing 配置项设置为 true 即可。

From 1.44, VS Code offers the built-in Rename On Type support for HTML and Handlebars that can be enabled with the setting editor.renameOnType. If this setting is enabled, this extension will skip HTML and Handlebars files regardless of the languages listed in auto-rename-tag.activationOnLanguage marketplace.visualstudio.com/items?itemN…

linked-editing__enabled

Word Separators (editor.wordSeparators)

此选项可以配置单词的分割规则,默认情况下,类似于 app_name 在进行单词相关操作(比如选中、删除单词等)时,会被判定为一个单词,因为 _ 不是 VS Code 的默认的单词分隔符:

work-separators__default

可以看到双击 zh_CN 的时候,整个 zh_CN 都能够被选中,但是双击 en-US 的时候,只能选中 en 或者 US,因为 editor.wordSeparators 的默认值为:

`~!@#$%^&*()-=+[{]}\|;:'",.<>/?

可以看到包含了 - 但是没有包含 _,将 _ 添加后,就可以将 zh_CN 判定为两个单词了:

work-separators__configured

Render Side By Side (diffEditor.renderSideBySide)

默认的差异编辑器是并排视图显示,设置 diffEditor.renderSideBySidefalse 后,就可以以内联视图显示,此配置也可以在编辑器右上角的菜单按钮中快捷设置:

render-side-by-side