How Do I Set Default Launch Folder? - visual-studio-code

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?

Related

Share VSCode data folder across OS systems

How can I share one Data folder between Windows and Linux Visual Studio Code on a multi-boot PC?
I want to have the same settings across both platforms, without having to set them up on each system individually.
VSCode on Windows (which is also downloaded as .zip so it's portable) stores all settings in a data folder, but I can't seem to make Linux version (downloaded as a portable .tar.gz file) use that same data folder that Windows version of VSCode uses.
What i mean by that, is when i make some setting change when i'm working in Windows, next time i boot up Linux, and start VSCode, i dont want to need to again change that same setting i applied on Windows VSCode already.
This is theoretically possible by using soft link on data directory, but it works partly.
Extensions are not loaded in Linux even if there is extensions folder in data folder, i downloaded some extension in Linux, and when i exit VSCode, extension disappears, while there are still some extensions in data from Windows VSCode.
I have custom theme in Windows VSCode, but it doesn't load in Linux at all.
I have online settings sync, but it doesn't sync everything. I want it to be synced by using literally same folder, so i don't feel any difference when switching OSes..

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?
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"
}
}

Auto-open a pinned file in VSCode

Context: I have a todo list file I always want to open as a pinned file in VSCode, but it's a pain having to reopen it manually for each project.
Is there any way to force VSCode to always open a particular file any time I open a new VSCode window?
Edit:
this should ideally work for all folders, as I often access remote folders over SSH that will not have workspaces created for them

How does VSCode's Remote Extension open files in my local editor through its internal terminal?

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.

Problem with saving and reopening a vscode workspace initiated from WSL

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?