【问题标题】:Key binding of custom snippet in vscode?vscode中自定义片段的键绑定?
【发布时间】:2018-10-15 09:47:45
【问题描述】:

VS 代码:1.28.1

Mac OS High Sierra 10.13.6

我创建了一个自定义 sn-p 来在 HTML 文件中添加插值。使用 F1 >insert sn-p 方式时它工作正常但我需要添加键绑定以便它与键盘一起使用。这是我所做的,但它不起作用。

vs code tutorial的帮助下创建一个sn-p

{
  "interpolate": {
    "prefix": "inter",
    "body": ["{{ ${CLIPBOARD} |json }}"],
    "description": "Interpolate this"
  }
}

现在我需要绑定快捷键并将其添加到 keybindings.json 中

{
    "key": "shift+cmd+i",
    "command": "editor.action.interpolate",
    "when": "editorTextFocus",
    "args": {
      "langId": "html",
      "name": "interpolate"
    }
  }

但是每当我点击 Cmd+Shift+I 时。抛出错误

“找不到命令'editor.action.interpolate'

我在这里做错了什么?

【问题讨论】:

    标签: visual-studio-code key-bindings vscode-extensions


    【解决方案1】:

    找到解决办法,我们需要在keybindings.json中添加name的值与用户sn-p文件html.json

    html.json

    {
      "interpolate": { // this is the name of snippet
        "prefix": "inter",
        "body": ["{{ ${CLIPBOARD} |json }}"],
        "description": "Interpolate this"
      }
    }
    

    keybindings.json

    {
        "key": "shift+cmd+I",
        "command": "editor.action.insertSnippet",
        "when": "editorTextFocus",
        "args": {
          "langId": "html",
          "name": "interpolate" << same as name of snippet
        }
      }
    

    【讨论】:

    • 你已经有了正确的“名字”。您需要更改的是“editor.action.isertSnippet”的命令。您的 sn-p 不会像您那样创建命令。
    • 这也需要更改 package.json。 “sn-ps”:[{“语言”:“html”,“路径”:“./sn-pFile.json”}]
    猜你喜欢
    • 1970-01-01
    • 2022-01-02
    • 1970-01-01
    • 2016-02-05
    • 2021-02-23
    • 2020-12-21
    • 2021-04-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多