How can a Visual Studio Code extension directly add key bindings

旧街凉风 提交于 2019-12-12 04:19:45

问题


Question

How can a Visual Studio Code extension add key bindings to a workspace directly?

Constraints

All settings should be contained within the extension, so that any modifications by the extension are easy to find in 1 place, and uninstalling the extension will remove any modifications.

Scenario

I'm developing a VSCode extension which will need to listen for keystrokes. This question listens through the vscode.workspace.onDidChangeTextDocument event, but I found that route a little messy in comparison to just creating key bindings for what I'm listening to. I found a pretty elegant way to achieve what I want using key bindings, but the implementation is not scalable and not simply exportable for others to implement.

Therefore I want to write an extension that totally encapsulates any key binding additions that are necessary.

I did find the answer to this after a long night of research, so I just want to post the solution for others' benefit.


回答1:


https://code.visualstudio.com/api/references/contribution-points#contributes.keybindings

This allows new keybindings to be declared right in the extension's package.json



来源:https://stackoverflow.com/questions/46615616/how-can-a-visual-studio-code-extension-directly-add-key-bindings

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!