When programming a vscode extension... Is there a programmatic way to find the keybinding for a provided command?
I would like to be able to see if a user has updated the key mapping from default for a command so that the UI can display the up-to-date binding. (and if not, look up the default binding)
Here are the APIs I've looked into so far:
vscode.workspace.getConfiguration()
- I cannot determine how to access the keybindings.json
file / perform a lookup.
vscode.extensions.getExtension(name/id)
allows access to the package.json
, but not the command or keybinding override.
vscode.getCommands
does not provide access to the keybinding values either...
You can get keybinding values from the keybindings.json file using NodeJS.
keybindings.json path on diferrent systems:
Windows: %APPDATA%\Code\User\keybindings.json
Mac: $HOME/Library/Application Support/Code/User/keybindings.json
Linux: $HOME/.config/Code/User/keybindings.json
To build the path you'll need to get Environment variables using process.env.{variableName}.
For example for MacOS it'll be:
var process = require('process');
//...
var keybindingsPath = process.env.HOME + "/Library/Application Support/Code/User/keybindings.json";
vscode.workspace.openTextDocument(keybindingsPath).then((document) => {
let text = document.getText();
//then use this JSON file for your needs
//...
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With