Kajiyama VK
Kajiyama VK

Reputation: 454

VS Code - open a file using the same window and keeping the workspace

I want a way to open/create files from the terminal - using the same VS Code Window.

If I try to give the following command using the terminal, it'll close the current window and open a new one.

code . nameofthefile.js -r --reuse-window

Then, if I'm running npm start - the previous command will kill it. On top of this - it'll reload my workspace removing all the folders that were in the Explorer on the left bar.

If I use only ..

code . nomeofthefile.js 

Is it possible to open a new file without closing the current with a terminal command in VS Code?

Upvotes: 14

Views: 16891

Answers (4)

Fuad All
Fuad All

Reputation: 975

you can use simple open command.

open filename.dart

Upvotes: 0

Gass
Gass

Reputation: 9344

To open a folder/file from the terminal in the same VSC window, do the following:

If you are in the folder/file directory:

code -r .

If you are NOT in the folder/file directory:

code -r folder/file-name

Replace folder/file-name with the name of your folder or file. If it's a file don't forget to add the extension.

Upvotes: 4

Shiv
Shiv

Reputation: 196

Open a folder in current vs code window while you are using the vs code terminal to change the directory:- code -r .

Upvotes: 15

M0nst3R
M0nst3R

Reputation: 5283

The VSCode command line (code) is able to open both folders and files depending on the path you provide. If you provide multiple paths, it will open all of them. If a path does not exist, it will create a new file for you at that location.

# open current folder as workspace
code .

# open file.js in the last used workspace
code file.js # or
code -r file.js

# open file.js inside current folder as workspace
code . file.js

Thus, according to the example you provided, you need to run code nameofthefile.js or
code -r nameofthefile.js (they both seem to do the same thing) to not override your current workspace.

Upvotes: 13

Related Questions