如何在指定的拆分视图中使用内置命令在VS Codium中打开特定文件?在不编写扩展的情况下可能会有可能吗?
我有一个项目,我定期想在拆分视图中以特定方式打开一对文件。让我们提到它们为 Qualide1.py
和 Quards1.txt
。我想在左侧以编程方式打开问题1.py,而Quards1.txt在右侧。
我找到了命令的文档 vscode.open
:
vscode.open-打开编辑器中提供的资源。可以是文本或二进制文件,也可以是HTTP(S)URL。如果您需要更多地控制打开文本文件的选项,请使用vscode.window.showtextdocument。
- URI-文本文档的URI
- columnoroptions-(可选)打开的列或编辑器选项的列,请参见vscode.textdocumentshowoptions
- 标签 - (可选)
- (返回) - 无结果
keybindings.json.json
i no no rest创建以下语句:
{
"key": "numpad4",
"command": "vscode.open",
"args": "/home/user/myproject/README.md"
},
{
"key": "numpad6",
"command": "vscode.open",
"args": ["/home/user/myproject/README.md", "1"]
},
现在,当我按 numpad4
时,它可以完美地运行,然后打开readme文件。但是,当我按 numpad6
时,我会收到一个通知:
无法打开'':发生未知错误。请咨询日志以获取更多详细信息。
我是否以错误的方式传递参数?为什么它不检测到文件名?而且我看不到要查看日志的鲸鱼。
附加信息:
VS代码版本:1.66.2。
我看到了一个CLI选项 -r, - reuse-window
,但它无法控制我要打开文件的视图。
我看到了类似的问题,但是作者想从扩展中做到这一点,而我希望不为此问题编写扩展名。另外,正如文档所说,我认为我不需要vscode.window.showtextdocument,因为vscode.open应该足以完成我的任务。
以下是可用ViewColumn值的枚举列表: htttps> htttps://code.visalstudio。 com/api/co点/vscode-api#viewcolumn
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
发布评论
评论(1)
结合 @riov8使用和 @mark的解决方案将两个命令组合到一个,将两个命令组合成一个,结果
keybindings.json 如下:
Combining the @rioV8's solution of using HTML Related Links and @Mark's solution for combining two commands into one, the resulting
keybindings.json
is the following: