68979

VSCode Open new view into file

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:

<pre class="lang-json prettyprint-override">"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" />

Recommend

  • How do I emulate a click on a div then fire the onclick event in webview programatically?
  • Extra curly braces while initializing a string
  • knitr hook to separate 000's, but not for years
  • Passing a view model with Server.TransferRequest()
  • Can you block a website from being in a browser's history?
  • Set cookies with Javascript to remember show state by click
  • How to make element scroll with you on page?
  • Python and PHP SOAP server
  • block scope extern declaration
  • pip installation of gmpy2
  • Trouble using Runtime.getRuntime().exec
  • How to delete/overwrite CSV file using google apps script?
  • Lookup song by ISRC in Apple Music/iTunes
  • One x-axis tick every 7 points
  • locationManager avoid (null) string in a Label
  • Share Application Through Facebook, Twitter, Email, and Messaging Only
  • How to bend a cylinder in three.js?
  • Encounter error “IB API required” when IB API is installed
  • SQL function not working when trying to write table to non-default schema
  • Tableview make specific cell or row editable
  • Launch Dash from Jupyter Notebook
  • OpenCV::solvePNP() - Assertion failed
  • Bulk loading into PostgreSQL from a remote client
  • Adding Dynamic Row and Data on Checkbox Click
  • I need a PHP mySQL Login script that directs user to specific URL based on username and password
  • Multiple canvases (pages) in Fabric.js
  • Sample deviceQuery cuda program
  • Find all parks for a given zipcode with google maps
  • content must have a ListView whose id attribute is 'android.R.id.list'
  • Excel File upload in asp.net using SqlBulkCopy
  • Magento-Change Attribute of All Products
  • When to use the tag in the head and body section of a html page? [duplicate]
  • Create an average of multiple excel chart without the data source
  • Cloud Code: Creating a Parse.File from URL
  • How to warp text around image in iOS?
  • JavaScript RegExp Replace