How to open folders in VSCode via Terminal in a fresh state?

Viewed 162803

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
19 Answers

this is the command that works for me on windows

code -r .

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.

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.

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 .

code . opens VS Code at the current terminal folder

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

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!

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 ."

I have the same problem on Mac.

I solved it in the following steps:

  1. I opened the "Command Pallete" on the VSCode. This can be done by CMD + SHIFT + P
  2. Type "shell"
  3. Click on 'Install code command in path'
  4. Give an administrator password
  5. You will get a message that it has been installed
  6. Now run "code ."
    NB: Make sure you already cd into the folder you want to open before you run 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.

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

This works for me with VSCode on Linux:

cd path/to/project
codium .

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.

I did it a simpler way just by three steps. I am currently in a project folder and want to open another folder in vs code using the cli or terminal. What I first did is navigated in the folder which I wanna open in vs code inside the terminal. Once I m inside that particular directory or folder I simply typed the command :

start code .

This will open that directory or folder in a new vs code window.

The complete process is :

  1. open the terminal is vs code

  2. navigate to the folder u want to open

  3. once u r inside that particular folder type the command :

    start code .

Go to the directory in the command pallet on your computer the navigate to the the specific folder using cd the type code . and that will open the folder and the files in it inside vs code. works like a charm.

If Visual Studio Code is installed using flatpak then a bash alias can help launch the application from the terminal.

alias code="flatpak run com.visualstudio.code"

Related