热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

如何在VSCode中为扩展设置键绑定?

如何解决《如何在VSCode中为扩展设置键绑定?》经验,为你挑选了2个好方法。

我正在使用VSCode编写Swagger(OpenAPI)规范,我想利用特定的扩展来帮助编写该规范.

我安装的扩展程序没有为我提供密钥绑定,可以轻松调用它.

如何添加密钥绑定?我试图通过单击文件 - >首选项 - >键盘快捷键并编辑keybindings.json文件来使其工作,但到目前为止没有成功.

我似乎必须发现扩展程序的命令,我不知道在哪里找到它,在我点击扩展集线器时,在扩展摘要页面上似乎不是很明显,然后在我要使用的扩展名上.



1> Get Off My L..:

如果您打开扩展程序的信息窗口,您可能会看到一个Contributions选项卡,在那里您可能会看到一个Commands列表.

在此输入图像描述

从那里你可以找到你想要的命令并在你的keybindings.json文件中绑定它File -> Preferences -> Keyboard Shortcuts

[
    {
        "key": "ctrl+enter",
        "command": "command.execute",
        "when": "editorTextFocus"
    }
]



2> Tore Aurstad..:

如果有人为VSCode编写了自己的扩展名,则可以使用keybindings属性以及内部的props属性来为命令设置默认的键绑定。由Yeoman yo code命令初始化的示例项目的package.json中的示例设置:

{
"name": "static-site-hero",
"displayName": "Static site hero",
"description": "Helps with writing posts for static site generator",
"version": "0.0.1",
"engines": {
    "vscode": "^1.30.0"
},
"categories": [
    "Other"
],
"activationEvents": [
    "onCommand:extension.helloWorld",
    "onCommand:extension.insertLink",
    "onCommand:extension.insertFigure"
],
"main": "./extension.js",
"contributes": {
    "commands": [
        {
            "command": "extension.helloWorld",
            "title": "Hello World"
        },
        {
            "command": "extension.insertLink",
            "title": "Insert Markdown Link to File or Image"
        },
        {
            "command": "extension.insertFigure",
            "title": "Insert HTML figure"
        }
    ],
    "keybindings": [
        {
            "command": "extension.insertLink",
            "key": "ctrl+alt+l",
            "mac": "shift+cmd+f",
            "when": "editorTextFocus"
        },
        {
            "command": "extension.insertFigure",
            "key": "ctrl+alt+F",
            "mac": "shift+cmd+l",
            "when": "editorTextFocus"
        }
    ]
},
"scripts": {
    "postinstall": "node ./node_modules/vscode/bin/install",
    "test": "node ./node_modules/vscode/bin/test"
},
"devDependencies": {
    "typescript": "^3.1.4",
    "vscode": "^1.1.25",
    "eslint": "^4.11.0",
    "@types/node": "^8.10.25",
    "@types/mocha": "^2.2.42"
}

}


推荐阅读
author-avatar
WE艺家人-千乐
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有