How to open folders in VSCode through the terminal in a new state?

It looks like VSCode always opens a folder with the last state of the user interface.

I am looking for something like Sublime remember_open_files: false , or, in other words, I would like VSCode to open with the clean state of the user interface regardless of what state the user interface was in the last time the folder was opened.

What is 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 
+15
source share
6 answers

I tried to do this through the command line using the command

 code -n . 

which was supposed to open VS code in the current folder with a new session, but it does not seem to work at all. I believe this code. seems to ignore the -n new session option and restore the previous session to the folder. So this function is probably not implemented in VS code.

(See here command line options for VS code.)

+13
source

I checked all the settings available in the VSCode settings for me, and I don't think there is a way to do this.

There are some settings related to the fact that the VSTode is a window into which folders will be opened, but nothing similar to the Sublime Text setting remember_open_files .

The closest I found is to run code --user-data-dir . (feel free to replace it with some other directory so that you don't pollute your current working directory) from the terminal to indicate that VSCode should not remember ANY previous settings, but that seems redundant for what you are trying to do (as VSCode will start literally as if it was the first time it started after a new installation).

EDIT : I just found the View: Close All Editors command in the command palette (CMD + SHIFT + P). The shortcut for OSX is CMD + K, CMD + W , and this will close all the files that you opened!

+2
source
 $ code . --user-data-dir=. 

This will open the Visual Studio code in the current working directory. I am using Bash with Ubuntu 16.04LTS.

+1
source

I am using VS Code version 1.24.1

If you want to open the folder through the terminal, you can execute the command:

code -n name_of_your_folder/ or code -n path_to your_folder/ similar for a file. This opens it in a new window.

Please note that you must have VS Code installed.

You are welcome!

0
source

Full and code command line interface (code) from an official document with a detailed list of supported arguments and examples of use. https://code.visualstudio.com/docs/editor/command-line#_opening-files-and-folders

Hope Helps

0
source

I followed the answer in this thread and it worked for me. Basically, make sure VSC is in the Applications folder. Then open the command palette (F1 or โ‡งโŒ˜P on Mac) and enter shell command to find the Shell Command: Install 'code' command in PATH command.

Restart Visual Studio Code if it is open. In the terminal, navigate to the folder that you want to open in VSC and enter code. Hope this should work for you.

0
source

All Articles