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?
Open a folder in current vs code window while you are using the vs code terminal to change the directory:-
code -r .
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With