VSCode打开文件的新视图

20

我们可以使用“分割编辑器”选项将两个视图合并为一个文件。

我正在寻找一种选项,可以像在Sublime Text中那样在不同的标签页中打开同一个文件。这个可能吗?

注意:我想要做到这一点而不需要拆分视图,所以应该在同一个视图容器中有两个用于同一文件的标签页。


这里的情况和之前一样,我仍然部分地使用Sublime,因为它允许在同一个文件上打开多个标签页。 - Dee
相关内容,请参见 https://stackoverflow.com/a/69111951/836330。类似的内容即将推出。 - Mark
1个回答

7

我无法找到任何内置的功能或者现有市场扩展能够实现这一点。我认为自己可以很容易地在自定义扩展中实现“Duplicate Tab”命令,但是事实证明VSCode只允许在同一视图列中打开相同资源一次

在Windows或macOS上仍然有可能实现这一点,但只能通过利用这个bug来进行:

Issues with not case/fragment-normalizing file paths (macOS, Windows) #12448

这是扩展的代码:

'use strict';
import * as vscode from 'vscode';

export function activate(context: vscode.ExtensionContext) {
    vscode.commands.registerCommand("duplicateTab", () => {
        var activeEditor = vscode.window.activeTextEditor;
        if (activeEditor == null) {
            return;
        }
        // HACK!
        const sameFileNameButDifferent = activeEditor.document.fileName.toUpperCase();
        vscode.workspace.openTextDocument(sameFileNameButDifferent).then(document => {
            vscode.window.showTextDocument(document, {preview: false});
        });
    });
}

package.json文件中:
"contributes": {
    "commands": [
        {
            "title": "Duplicate Tab",
            "command": "duplicateTab"
        }
    ]
},


扩展程序在这里,但是它不再起作用:https://marketplace.visualstudio.com/items?itemName=kxkx5150.new-view-into-file - Dee

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接