How to open folders in VSCode via Terminal in a fresh state?
Visual Studio-CodeVisual Studio-Code Problem Overview
It appears that VSCode always opens a folder in with the last UI state it had.
I'm looking for something like Sublime's remember_open_files: false
, or in other words, I would like VSCode to open up with a clean UI state regardless of what state the UI was in the last time the folder was open.
What's happening now:
cd my-project-folder/
code .
# VSCode opens folder with saved UI state
What I want:
cd my-project-folder/
code .
# VSCode opens folder with fresh UI state
Visual Studio-Code Solutions
Solution 1 - Visual Studio-Code
I tried to do it through command line using the command
code -n .
which should have opened VS code in current folder with a new session but it does not seem to work at all. I believe that code .
seems to ignore the -n
new session option and restores the previous session for the folder. So this feature is probably not implemented in VS code.
(Refer here for the commandline options for VS code.)
Solution 2 - Visual Studio-Code
this is the command that works for me on windows
code -r .
Solution 3 - Visual Studio-Code
From inside VS Code built-in terminal, cd into your project folder/directory and enter command:
code -a .
Note period at end.
This will open your current directory/project folder without opening a new window.
Solution 4 - Visual Studio-Code
Part of the answer on this thread worked for me. Basically, make sure VSC is in the Applications folder. Then open the Command Palette (F1 or ⇧⌘P on Mac) and type shell command
to find the Shell Command: Install 'code' command in PATH command.
Restart Visual Studio Code if it's open. In terminal, navigate to the folder you want to open in VSC, and type code .
. Hopefully it should work for you.
Solution 5 - Visual Studio-Code
if you are using a mac you need to first install the VScode command amongst the shell command list.
Do this:
Open VCode
press CMD + SHIFT + P
type 'shell command'
select 'Install code command in path'
navigate to any project from the terminal and type 'code .'
Solution 6 - Visual Studio-Code
code .
opens VS Code at the current terminal folder
Solution 7 - Visual Studio-Code
If you are using VS Code [Version: 1.50.0] then open your command prompt and go to your project's directory and just run the command:
code -a .
i.e. [Also can see the photo] [1]: https://i.stack.imgur.com/sMmkH.png
Solution 8 - Visual Studio-Code
$ code . --user-data-dir=.
This will open Visual Studio Code in current working directory. I use Bash with Ubuntu 16.04LTS.
Solution 9 - Visual Studio-Code
I checked through all of the settings available in the VSCode preferences for me, and I don't think there is a way to do this.
There are some settings related to what VSCode window instance that folders will open into, but nothing that seems similar to Sublime Text's remember_open_files
setting.
The closest thing I found was running code --user-data-dir .
(feel free to replace .
with some other directory so you don't pollute your current working directory) from the terminal to specify that VSCode shouldn't remember ANY previous settings, but this seems like overkill for what you're trying to accomplish (as VSCode will literally run as if it's the first time it's being run after a fresh install).
EDIT: I just discovered a View: Close All Editors
command in the command palette (CMD + SHIFT + P). The keyboard shortcut for OSX is CMD + K, CMD + W
, and this will close all the files you have opened!
Solution 10 - Visual Studio-Code
I am using VS Code Version 1.24.1 (As of the time of original posting).
If you want to open a folder through the terminal, you can execute the command:
code -n name_of_your_folder/
or
code -n path_to your_folder/
Same thing goes for a file, and these open VS Code in a new window.
Also, note that you should have VS Code installed.
You're welcome!
Solution 11 - Visual Studio-Code
If you want to open folder with vscode, you just go to folder ( you can user terminal or file explorer) with terminal, and do "code ."
Solution 12 - Visual Studio-Code
I have the same problem on Mac.
I solved it in the following steps:
- I opened the "Command Pallete" on the VSCode. This can be done by CMD + SHIFT + P
- Type "shell"
- Click on 'Install code command in path'
- Give an administrator password
- You will get a message that it has been installed
- Now run "code ."
NB: Make sure you already cd into the folder you want to open before you run code .
Solution 13 - Visual Studio-Code
To get the right folder in VS Code v 1.50.1 Terminal I tried a lot of options which didn't work for me. At the end I found very easy solution. I went to File->Open Workspace and found that my Workspace had the wrong folders inside it, which I simply deleted (from Workspace only!). Then I opened the folder I needed in my Workspace, opened Terminal->New Terminal, and everything worked perfectly well. Please let me know if this will work for someone else.
Solution 14 - Visual Studio-Code
This command works to open a specific folder in VS code using terminal
code -r Documents/VS/C++/
here -r switch is used to open a file or a folder in an already opened VS code window and then you specify the path of the file or folder you want to open if you want to open it in a new window use -n switch instead of -r
Solution 15 - Visual Studio-Code
This works for me with VSCode on Linux:
cd path/to/project
codium .
Solution 16 - Visual Studio-Code
I tried every mentioned answers, what's work from me is this:-
I created a shell script to open folders.
$ sudo nano /usr/local/sbin/code2
/usr/bin/code-oss -n --user-data-dir '/home/myusername/.config/Code - OSS2/' -a $@
$ sudo chmod +x /usr/local/sbin/code2
You can remove --user-data-dir '/home/myusername/.config/Code - OSS2/'
from the script if you want to use default code-oss config folder.
When I want to open a folder, I use the command like this :-
$ code2 .
I add this command code2
to open with option thunar
to open folders directly from files manger.