I have an absolute path to a file (/path_to_file/file.file
) embedded in my code, which is open in the VS Code editor. I want to create a shortcut to quickly open this file by either just clicking on the path or highlighting the path and pressing a shortcut.
// my code blabla
file = "/path_to_file/file.file"
I have something like this in mind, only it does not work:
keybindings.json:
[
{
"key": "ctrl+y",
"command": "editor.action.openFileAtPath",
"when": "editorTextFocus"
}
]
The command editor.action.openFileAtPath
does not exist. Is there an alternative?
I have tried creating an own snippet:
{
"OpenFilePath": {
"prefix": "openfile",
"body": [
"const filePath = \"$TM_SELECTED_TEXT$\";",
"vscode.workspace.openTextDocument(filePath).then(doc => {",
" vscode.window.showTextDocument(doc);",
"});"
],
"description": "Open the selected file path"
},
and using it with keybindings:
{
"key": "ctrl+y",
"command": "editor.action.insertSnippet",
"when": "editorTextFocus",
"args": {
"langId": "",
"name": "OpenFilePath"
}
}
This, however, only replaces the highlighted text with the content of the snippet, but does not execute it. How can I achieve that?