在VS Codium中指定的ViewColumn中打开文件的命令是什么?

发布于 2025-01-26 22:50:52 字数 1980 浏览 4 评论 0 原文

如何在指定的拆分视图中使用内置命令在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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

喵星人汪星人 2025-02-02 22:50:52

结合 @riov8使用和 @mark的解决方案将两个命令组合到一个,将两个命令组合成一个,结果 keybindings.json 如下:

    {
        "key": "numpad5",
        "command": "extension.multiCommand.execute",
        "args": {
            "sequence": [
                {   "command": "htmlRelatedLinks.openFile",
                    "args": {
                        "file": "/home/user/myproject/problem1.py",
                        "method": "vscode.open",
                        "viewColumn": 1,
                    }
                },
                {   "command": "htmlRelatedLinks.openFile",
                    "args": {
                        "file": "/home/user/myproject/problem1.txt",
                        "method": "vscode.open",
                        "viewColumn": 2,
                    }
                },
            ]
        }
    },

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:

    {
        "key": "numpad5",
        "command": "extension.multiCommand.execute",
        "args": {
            "sequence": [
                {   "command": "htmlRelatedLinks.openFile",
                    "args": {
                        "file": "/home/user/myproject/problem1.py",
                        "method": "vscode.open",
                        "viewColumn": 1,
                    }
                },
                {   "command": "htmlRelatedLinks.openFile",
                    "args": {
                        "file": "/home/user/myproject/problem1.txt",
                        "method": "vscode.open",
                        "viewColumn": 2,
                    }
                },
            ]
        }
    },
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文