Is there a way to discover the current key bindings for a command? #780
-
I have an extension with some placeholder text, added using a text editor decoration:
However, the user might have changed the key binding. Is there some way to find out what the actual key binding is for a command? Ideally the message would be customized for the actual keyboard they're using. I don't see any API related to key bindings. (I asked GPT4 and it hallucinated one.) |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hi @skybrian I'm not aware that there is a direct API in VS Code for querying the current keybindings from within an extension. However, you can consider the following workaround to accomplish this:
Hope this help a bit. |
Beta Was this translation helpful? Give feedback.
Hi @skybrian
I'm not aware that there is a direct API in VS Code for querying the current keybindings from within an extension.
However, you can consider the following workaround to accomplish this:
Load Keybindings from User Settings:
VS Code stores its keybindings in a JSON file. The extension can read the user's keybindings by loading the
keybindings.json
file from the user's settings directory. The path to this file can vary based on the platform (Windows, Mac, or Linux).Once you've read the file, you can search within the JSON data for the command you're interested in and then extract the keybinding.
Keep a Default Text:
If you're unable to determine the custom keybinding …