carlfriedrich
carlfriedrich

Reputation: 4019

Visual Studio Code: shortcut to open a certain file

I have a text file on my local drive in which I like to take random notes. I want to be able to quickly open this file in VS Code from every project I work on. The Ctrl+P shortcut only shows files which had already been opened before in the current workspace, so the first time I open the file in a new workspace I still have to open it manually.

Does anybody know an extension or any built-in functionality providing a quick way to open a certain file that has not been opened before? My ideal solution would be a dedicated hotkey that just opens a configurable file.

I've searched the marketplace and tried several "favorites" extensions. None of them provides what I'm looking for.

The pitfall is that the solution has to work for local files in remote workspaces as well, i.e. I am connected to a remote server via VS Code's remote SSH extension and still want to open the file from my local filesystem.

Any ideas?

Upvotes: 0

Views: 1752

Answers (1)

rioV8
rioV8

Reputation: 28623

You can try the extension HTML Related Links v0.15.1 and the command htmlRelatedLinks.openFile to open a local file. Specify the full path.

At first I did not had this extension installed in the remote computer. VSC complained that the command htmlRelatedLinks.openFile did not exist. That means that the VSC remote window uses the local key binding file but executes the commands on the remote machine. This means you have different key bindings if you are at the physical keyboard of the remote machine compared to a remote connection. The same goes if you have set your XDISPLAY (??) environment variable (for Linux systems, remote display)

You tried it with v0.14 (see comment) and found out that VSC uses the scheme vscode-remote (not documented).

I modified the extension so we can set the scheme of the URI.

Using scheme file did not work. In local VSC all local file URIs have this scheme.

But if we use the scheme vscode-local (that you have found somewhere) I was able to open a file from the local disk in the remote VSC instance with a key-binding.

  {
    "key": "ctrl+i n",  // or any other combo
    "command": "htmlRelatedLinks.openFile",
    "args": {
      "file": "C:\\Projects\\Notes\\notes.txt",
      "method": "vscode.open",
      "viewColumn": "split",
      "useScheme": "vscode-local"
    }
  }

Upvotes: 2

Related Questions