
Question:
We can use the "split editor" option to make two views into one file.
I'm looking for an option to open the same file in separated tabs like I can do in Sublime Text (open new view of file). Is that possible?
Note: I want to do this <strong>without splitting the view</strong>, so there should be two tabs for the same file within <em>the same</em> view container.
Answer1:I couldn't find anything built-in that lets you do this, nor an existing extension in the marketplace. I thought it should be quite trivial to implement a "Duplicate Tab" command yourself in a <a href="https://code.visualstudio.com/docs/extensions/overview" rel="nofollow">custom extension</a>, but It turns out <strong>VSCode only allows the same resource to be opened <em>once</em> within the same view column</strong>.
It's still possible to do this on Windows or macOS, but only by abusing this bug:
<a href="https://github.com/Microsoft/vscode/issues/12448" rel="nofollow">Issues with not case/fragment-normalizing file paths (macOS, Windows) #12448</a>
Here's what the code for the extension looks like:
<pre class="lang-ts prettyprint-override">'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});
});
});
}
In package.json
:
"contributes": {
"commands": [
{
"title": "Duplicate Tab",
"command": "duplicateTab"
}
]
},
<img alt="" class="b-lazy" data-src="https://i.imgur.com/ytax0Qv.gif" data-original="https://i.imgur.com/ytax0Qv.gif" src="https://etrip.eimg.top/images/2019/05/07/timg.gif" />