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?
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"
}
}
Related
I want VSCode to always open the same folder when I launch it. The current behavior is to launch whatever folder VSCode thinks I last visited.
I maintain notes that are kept in folders on the same system that I run my local VSCode instance from. All of my development is on remote systems that are often not running when I launch VM. In a development session, I often have many (5-10) files open in VSCode on various source, config, and data files -- often on multiple remote systems. These remote systems are frequently not even running when I next launch VSCode.
When I launch VSCode, I want VSCode to always open (from the desktop) my local "notes" folder, where I keep my daily journal files. I want to then open folders on remote systems -- most often using the "File -> Open Recent" command.
I do not see anything in settings.json or in preferences that lets me control what folder is open on startup.
How do I configure VSCode so that it always opens the same (local) folder on startup, regardless of what files I was editing when I last closed it?
I’m trying to add a couple of key-bindings to my codespace image. But I can’t find where to store the keybindings.json, when I open the file in an active codespace it’s located in /User/keybindings.json, but I can’t find it in bash or when I try to Open Folder that folder. It seems to be a virtual file.
Is there a way to add these to the devcontainer.json? Or a magic place I can send them to from my Docker File?
Based on a number of closed issues, keybindings are considered more a personal preference and are synced from the users' preferences as well as platform dependent.
To supply or override keybindings a custom extension must be created, published to the marketplace and installed through the devcontainer.json.
I use VSCode's remote development extension fairly regularly. I can use the terminal in VS Code as if it were on my own machine, and even the code command works correctly. That is, when I'm in a remote VSCode session, I can type code path/to/some/file and it will open another editor tab with that file. The terminal session and the file being opened are on the remote machine to which I've connected.
I have VSCode installed on the remote machine, and the code executable is in my PATH. So my question is, how is this functionality implemented behind the scenes? That is, how does VSCode know that when I type code path/to/some/file it should open that file into another editor tab on my machine instead of trying to fire up VSCode on the remote machine?
Literally seconds after I wrote the question I found the answer.
If I run which code in the terminal, it doesn't resolve to the usual VSCode executable, but instead it resolves to one located at $HOME/.vscode-server/bin/a5d1cc28bb5da32ec67e86cc50f84c67cc690321/bin/code.
If I echo $PATH I can see that $HOME/.config/bin and $HOME/.vscode-server/bin/a5d1cc28bb5da32ec67e86cc50f84c67cc690321/bin has been appended to the beginning of the PATH env var that my bash profile generates.
I assume this means that VSCode is executing bash with a different profile script that
Sources my usual bash profile
Creates the directories above and copies some helper programs into them
Modifies my path to include these directories
I also assume that the injected code executable is communicating with my local instance of VSCode in some way, instructing it to open the file in its editor.
I open my vscode with code . command from WSL terminal because I want to work directly in my WSL. It works fine and for example, the file explorer of vscode shows directory structures based on WSL machine and not based on my Windows machine.
My problem is however that, when I save a workspace using File -> Save Workspace As, it saves it again as a workspace in my Windows machine. So when I close and open my vscode again and use Open Workspace... to open the already saved workspace(in previous step), explorer reads directories from Windows machine.
You might ask what's the difference between saving files in /mnt/c/Users/[user]/Desktop or C:\Users\[user]\Desktop, but the problem is two things:
I might open a session from a directory in WSL that is (unlike Desktop) inaccessible from Windows.
Even if my Desktop is my current working directory, I may add another directory to my workspace (using Add Folder to Workspace...) and even if it is a path accessible from Windows, the next time I open the workspace, I will get an exclamation mark and such an error near that directory in explorer:
C:\mnt\d\Files_And_Downloads\Google Drive_Code . Can not resolve workspace folder
I suspect this is a bug, vscode has mixed the WSL path and Windows path. So anyone who uses Remote - WSL extension and can tell me what's going on here?
TRAMP (Transparent Remote Access, Multiple Protocols) is a package for editing remote files, similar to AngeFtp or efs. Whereas the others use FTP to connect to the remote host and to transfer the files, TRAMP uses a remote shell connection (rlogin, telnet, ssh). It can transfer the files using rcp or a similar program, or it can encode the file contents (using uuencode or base64) and transfer them right through the shell connection.
It seems like as of now there is at least one similar package to Tramp mode for VSCode. I couldn't directly find in the documentation how you would open a remote shell inside VSCode, but it seems like it would have to be possible given the rest of the plugin.
https://code.visualstudio.com/docs/remote/ssh
https://code.visualstudio.com/blogs/2019/10/03/remote-ssh-tips-and-tricks
I have a terminal menu in VSCode that I can open up and directly ssh to stuff, so that seems to cover both sides of the "Tramp" mode usage
You can use FUSE for a somewhat similar effect. It's not editor specific, but mounts remote file systems via SSH, FTP and whatnot directly to your local file system so you can use it with any Editor.
You didn't mention on what operating system you, but here's the link to the version for macOS: https://osxfuse.github.io