'Keybinding to open a specific file in vscode
I presume this is achievable through editing keybindings.json
. As I can't seem to find a list of available commands, I've got this far through auto-complete:
{
"key": "SHORTCUT",
"command": "workbench.action.files.openFile",
"args": {
// ARG TO POINT TO SPECIFIC FILE
}
}
Seems a simple task but I can't seem to find the documentation I'm after. If someone could also point me to the relevant docs I'd be grateful.
Solution 1:[1]
I was also looking for this and reading the source code
vscode/src/vs/workbench/browser/actions/workspaceActions.ts
It does not use arguments and straight calls a dialog service to show the FileOpen dialog of the OS.
I have made an Open File command in the extension HTML Related Links possible to be called from a keybinding.
{
"key": "ctrl+i ctrl+o", // or any other key binding
"command": "htmlRelatedLinks.openFile",
"args": [ "/home/mememe/Projects/Python/README.md", 10, 5 ]
}
Solution 2:[2]
Here's a way to do it using a vscode shortcut:
- Open keybindings from the command palette
Preferences: Open Keyboard Shortcuts (JSON)
- Add the following JSON:
{
"key": "ctrl+m",
"command": "workbench.action.terminal.sendSequence",
"args": {
"text": "code ~/.vscode/notes.txt\u000D"
}
}
- Replace the above json with the file you'd like to open and your desired shortcut
- Profit
Solution 3:[3]
And here's perhaps the simplest and fastest way to do it (via an extension):
https://marketplace.visualstudio.com/items?itemName=tgreen7.open-file-command
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | rioV8 |
Solution 2 | tnrich |
Solution 3 | tnrich |