VS Code 自定义联想输入词库?

2021-03-20 04:59:36 +08:00
 dLvsYgJ8fiP8TGYU

由于需要编辑一些程序的配置文件,且经常需要输入固定的一些(不超过 10 组)变量名称(很长,不好手打),希望有什么方法 /插件可以简化输入过程。

目前使用的 vscode intellisense 有联想 /自动补全功能。但似乎只能从当前文件所使用的语言对应的关键词 list 中显示,或者从上下文「已经存在的」变量名中选择补全,因此第一次输入的时候还是没法自动化;

系统输入法自定义词库似乎也在 vscode 界面无法触发;

还有啥方法能在 vscode 里面自定义词库的?看了一下 intellisense 的文档没发现类似功能

1634 次点击
所在节点    程序员
7 条回复
codehz
2021-03-20 05:18:17 +08:00
你可能需要的是 snippet
可以使用类似这样的写法指定在哪些语言生效
{
"My Awesome Snippet": {
"prefix": "abc",
"lang": ["css", "php", "html"],
"body":[
"abc123!@#"
]
}
}
codehz
2021-03-20 05:36:10 +08:00
上面的例子当我没说,看了一眼并不能声明多个语言,不过你可以手动写好几份,反正都是一次性编写的事情
noqwerty
2021-03-20 05:47:44 +08:00
@codehz #2 可以在 global snippet file 里面定义:Multi-language and global user-defined snippets are all defined in "global" snippet files (JSON with the file suffix .code-snippets), which is also accessible through Preferences: Configure User Snippets. In a global snippets file, a snippet definition may have an additional scope property that takes one or more language identifiers, which makes the snippet available only for those specified languages. If no scope property is given, then the global snippet is available in all languages.

参考链接: https://code.visualstudio.com/docs/editor/userdefinedsnippets#_language-snippet-scope
Trim21
2021-03-20 05:56:40 +08:00
如果是编辑 JSON toml 这类的配置文件可以写个 JSON schema
molvqingtai
2021-03-20 10:06:24 +08:00
有个人工智能补全插件挺好用的,就是有点耗内存 https://github.com/codota/tabnine-vscode
imrealadmin
2021-03-20 10:07:36 +08:00
vscode 支持多个文件的关键词推荐的,配置如下:

```json
"editor.wordBasedSuggestions": true,
"editor.wordBasedSuggestionsMode": "allDocuments",
```
dLvsYgJ8fiP8TGYU
2021-03-20 21:25:58 +08:00
@codehz 感谢,已经用 snippet 实现了自定义词库

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/763368

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX