How can I open a specific file in a specified split view with an built-in command in VS codium? Is that possible without writing an extension?
I have a project, and I periodically I want to open a pair of files in specific way in split view. Let's mention them as problem1.py
and problem1.txt
. I want to programmatically open problem1.py in the left side, and the problem1.txt in the right side.
I found an a documentation for the command vscode.open
:
vscode.open - Opens the provided resource in the editor. Can be a text or binary file, or an http(s) URL. If you need more control over the options for opening a text file, use vscode.window.showTextDocument instead.
- uri - Uri of a text document
- columnOrOptions - (optional) Either the column in which to open or editor options, see vscode.TextDocumentShowOptions
- label - (optional)
- (returns) - no result
In keybindings.json
I created following statements:
{
"key": "numpad4",
"command": "vscode.open",
"args": "/home/user/myproject/README.md"
},
{
"key": "numpad6",
"command": "vscode.open",
"args": ["/home/user/myproject/README.md", "1"]
},
Now when I press numpad4
, it works perfectly, the readme file opens. But when I press numpad6
, I get a notification:
Unable to open '': An unknown error occurred. Please consult the log for more details.
Am I passing parameters in a wrong way? Why it does not detect a filename? And I do not see whare to view a log.
Additional info:
VS codium version: 1.66.2.
I saw a cli option -r, --reuse-window
, but it has not control of in which view I want to open a file.
I saw a similar question, but there the author wants to do it from extension, while I would prefer to not write an extension for this problem. Also, as documentation says, I think I do not need vscode.window.showTextDocument, as vscode.open should be enough for my task.
Here is an enum list for available ViewColumn values: https://code.visualstudio.com/api/references/vscode-api#ViewColumn
htmlRelatedLinks.openFile
– Bloke"viewColumn": 1
, maybe have to adjust the README to make it clear – Blokevscode.open
command was not really intended for use outside an extension. Note that the first argument is auri
which you wouldn't normally have easy access to except in an extension. [That was later relaxed to a simple path string, but the documentation was never updated.] This is why there are a number of extensions to do this, butHTML Related Links
appears to handle the viewColumn arg whereas some others don't. – Kamikamikaze