V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
dLvsYgJ8fiP8TGYU
V2EX  ›  程序员

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

  •  
  •   dLvsYgJ8fiP8TGYU · 2021-03-20 04:59:36 +08:00 · 1618 次点击
    这是一个创建于 1127 天前的主题,其中的信息可能已经有所发展或是发生改变。

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

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

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

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

      • -最后有一个大胆的想法:根据不同文件拓展名 [.ext01, .ext02...],匹配不同的词库 [list01, list02...] (就是不知道有没有人真的做出了这样的插件了)
    7 条回复    2021-03-20 21:25:58 +08:00
    codehz
        1
    codehz  
       2021-03-20 05:18:17 +08:00   ❤️ 1
    你可能需要的是 snippet
    可以使用类似这样的写法指定在哪些语言生效
    {
    "My Awesome Snippet": {
    "prefix": "abc",
    "lang": ["css", "php", "html"],
    "body":[
    "abc123!@#"
    ]
    }
    }
    codehz
        2
    codehz  
       2021-03-20 05:36:10 +08:00
    上面的例子当我没说,看了一眼并不能声明多个语言,不过你可以手动写好几份,反正都是一次性编写的事情
    noqwerty
        3
    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
        4
    Trim21  
       2021-03-20 05:56:40 +08:00 via Android
    如果是编辑 JSON toml 这类的配置文件可以写个 JSON schema
    molvqingtai
        5
    molvqingtai  
       2021-03-20 10:06:24 +08:00
    有个人工智能补全插件挺好用的,就是有点耗内存 https://github.com/codota/tabnine-vscode
    imrealadmin
        6
    imrealadmin  
       2021-03-20 10:07:36 +08:00
    vscode 支持多个文件的关键词推荐的,配置如下:

    ```json
    "editor.wordBasedSuggestions": true,
    "editor.wordBasedSuggestionsMode": "allDocuments",
    ```
    dLvsYgJ8fiP8TGYU
        7
    dLvsYgJ8fiP8TGYU  
    OP
       2021-03-20 21:25:58 +08:00
    @codehz 感谢,已经用 snippet 实现了自定义词库
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2874 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 03:55 · PVG 11:55 · LAX 20:55 · JFK 23:55
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.