How to change folder that opened by default in VSCode? - visual-studio-code

I have small problem with VSCode folder, that opened by default.
Problem description: I start new instance of VSCode (trough File->New Window), and then if I choose File->Open Folder it opens dialog with my Windows user folder as starting point (C:\Users\MyUser)
Question: How can I change that folder in settings (if it possible)? So by default it will show as start point for example D:\development\ ?

At the time I write this answer, this is not possible. There are two problems on Windows, and one problem on Mac and Linux:
VS Code does not provide a default path to the file dialog 1. It does remember the last folder that you opened a file in, but that path cannot be used as a default because it is overwritten constantly.
On Windows only, Electron ignores the default path when creating a file dialog if the default path is a directory 2.
An extension also cannot solve this, because extensions are not allowed to modify the File menu 3.
I think the best option at this point is to pin a folder to the Quick Access area in Windows Explorer, as suggested in a comment, or to put an actual shortcut in the user profile folder.
Workspaces and File > Open Recent may also be helpful if you often open the same folders.

Your main problem is that you are unable to open your specific folder in VScode.
To solve that you can simply open the terminal/cmd in that specific window by just typing cmd in your search bar or just by pressing shift+right-click in that folder.
Now your cmd is open and you just have to type "code ." in the cmd and press enter to open the current folder in your VSCode.
In case that code . doesn't work for you then you have to add the Vscode in the environment variables of your windows.

Visual Studio doesn't provide a specific feature to open a specific path. But there is a solution to your problem. You are saying that you want D:\develpment as a default when you open VS Code. You can go to that specific directory or create shortcut to desktop then click right click on that folder and then click on open with code. If you didnot see open with code then reinstall your VS code and check on open with code when you are reinstalling VS Code.

make a shortcut on the desktop for vscode and then modify it and add the folder after the .exe command. This will default open that folder when you double click on it.

Visual Studio Code can be installed in two ways - User setup and System setup. I strongly believe you have User setup installed in your PC. Try re-installing it System-wide. That should probably fix your problem.
For more information: https://code.visualstudio.com/docs/setup/windows#_user-setup-versus-system-setup
PS: A lot more information is needed, you can share a screenshot of the window and elaborate more on it.

Related

Renaming files doesn't take effect in VScode while using WSL2

I have a very annoying problem in my VScode setup.
I'm using WSL as a terminal to work on my projects and occasionally, mistype the name of one of the folder or file that I'm working with.
For example:
I accidentally created the Mainheader.js file in layout folder (without the capitalized L) therefore, I decided to rename the folder with a capital L.
Now on my React app, any changes made to MainHeader.js file will not be reflected. I did update the related import.
So I decided to delete the entire folder and recreate it with MainHeader.js but this is what I end up with.
The file is there in my folder but when I click on it, I get
"Unable to open Mainheader.js - File not found"
So I try to create it then I get this error:
Unable to create file 'wsl\path]to\MainHeader.js' that already exists when overwrite flag is not set
Has anyone run into this type of behavior in WSL before? It's quite annoying because the only workaround I've found so far is to create a completely different folder with a different name...
Any help would be appreciated. I can't really work like this.
I've been having the same problem for the past 2 days. I presume its a permissions issue, but unfortunately I don't know how to permanently fix it.
I did find this work-around though:
Open a new VS Code window. (I'd recommend closing any VS Code window that had
your project directory open.)
Create a duplicate or copy the contents of the problem file so you don't lose
your code.
Delete the problem file.
Now create the file again using VS Code. Go to File > New Text File. Next paste
in your code.
Now save your new file. Go to File > Save As and save your new file with at the same path + filename + extension that was giving you problems previously. VS Code should allow you to save the new file without any issue.
Now you can open this new VS Code window to your project directory and you should be able to continuing accessing the file that was a problem before.
Basically we just deleted the problem file and then created it again from scratch in a new VS Code window.
Hope this work-around works for you!
EDIT 09/20/2022
Following Baza86's answer here solved the issue for me. Seems like it was a permissions issue of sorts, but if you use the Remote-WSL extension VS code can directly access the linux filesystem.
How to run VScode in sudo mode in WSL2?
You may need add the case option to you options in the wsl config. The default is set to off, however you can set this to off, dir or force.
Open your wsl.conf using sudo with any text editor while running window subsystem Linux. The config file resides in /etc/wsl.conf. This file is used to configure settings per-distribution for Linux distros running on WSL 1 or WSL 2.
My default config looked like this yours may be different:
[automount]
options = "metadata"
add
[automount]
options = "metadata,case=dir"
Here is the official Microsoft docs for Advanced settings configuration in WSL - https://learn.microsoft.com/en-us/windows/wsl/wsl-config

VSCode highlight PWD in Explorer

Contrary to changing the terminal to the present working directory in VSCode, I'm looking for a way to get the present working directory in the focused integrated terminal and then highlight it in the Explorer. One way to do this would be using code ., but that opens up a new workbench if you're in a child directory. Is there a native way or an extension that supports doing this? Both command palette and keyboard shortcuts would work.
So far, I can't find any APIs for:
Reading the CWD from the active terminal.
Changing the selected file in Explorer.
A workaround is to use code ./some-file to open it in the active Explorer.

Why does "Open with Code" appear twice in the context menu?

When I right click a file, I see Open with Code twice. I know one of them is from the actual Visual Studio Code installation. When I uninstalled VSCode, I noticed the the number 1 in the screenshot below remained. Where is it that coming from and how do I get rid of it?
It looks like you have a lingering context menu item from a previous Visual Studio Code install. Try the following:
Open your registry editor. You can find this by searching for "regedit" in the Windows search bar.
Navigate to Computer\HKEY_CLASSES_ROOT\Directory\shell
Look for the VSCode folder.
If you see two VSCode folders at this point, open them up and see if one is pointing to a Code.exe that no longer exists. If that's the case, simply delete the folder for the nonexistent install and your problem should be fixed.

Make Visual Studio Code open in clean state

I work in multiple projects spread in multiple folders on macOS.
I usually start working on them by running:
cd ~/workspace/project-a
code .
That always causes a new window to be open with the last files I worked on that project. My next move is to close all tabs, if the editor was split I have to do that as many times as split editors I had.
Is there a setting that would allow me to always start on a clean state?
My settings that I believe are related to this issue are the following:
"window.restoreWindows": "none",
"files.hotExit": "onExitAndWindowClose",
I tried off for files.hotExit but the behaviour remained the same.
Also if possible, where is this information stored (open files for given folders)? Is that a dot file inside the folder or elsewhere inside Visual Studio Code installation?
Make sure you are on the latest VSCode (1.24.1 as on 18-Jun-18)
Then make sure you have below in your settings
"window.restoreWindows": "none",
Make sure there are no JSON errors in your custom settings file. This also could cause the settings to be not loaded at all.
Next try launching the folder using
code -n .
Also $HOME/Library/Application Support/Code/Backups/workspaces.json contains the information of open workspaces
Also refer to below thread
Visual Studio Code always reopens previous file or folder
You could try, in addition of the setting "window.restoreWindows": "none" to start with:
code -n
That would force a new VSCode Window to be opened.
Also if possible, where is this information stored (open files for given folders)?
See issue 3884
# Windows
%APPDATA%\Code\Workspaces
# Mac
$HOME/Library/Application Support/Code
$HOME/Library/Application Support/Code/Workspaces
$HOME/Library/Application Support/Code/Backups/workspace.json
Window > Open Folders In New Window
set it to off

Install VSCode in a specific folder

I just downloaded the Visual Studio Code App from https://code.visualstudio.com/ and when I tried to install it, it simply just installed it by itself, without the option to change the installation path.
I have an external harddrive, which is where I want the IDE to be placed instead of the Local Harddrive. How can I change this?
On the VSCode download page select "System Installer" instead of "User Installer". The System installer will prompt you for the install location.
Full credit to Hans Passant for giving the following working solution as a comment.
The installer does very little beyond copying the files, it just creates some Explorer context menu shortcuts ("Open with Code"). Otherwise following Chromium conventions and copying itself to c:\Users\yourname\AppData\Local\Code\app-0.1.0 so it can update itself without you noticing. Boo. So high odds that simply moving that folder to the other drive works just fine, put it anywhere and create a shortcut to Code.exe. If you still want the context menu entry to work then use Regedit and search for "code\app-0.1.0".