Open folders on Current Visual Studio Code Window from terminal

Published 09-12-2019 10:19 PM 17.5K Views
Microsoft

I usually used `code .` command to open a folder using Visual Studio Code, however it open as new Window.

So, I used folder open dialog to open a folder by current Window. GUI is useful. But I sometime had felt that I don't want to leave terminal window.

The solution!!

I checked a following document. I found -r option and --add option!!

https://code.visualstudio.com/docs/editor/command-line

 

-r option is to open a folder by current window, --add option is to add a folder to current work space.

If I would like to add two folders to Visual Studio Code, the folder names are 'sample1' and 'sample2', and initialize as git repositories.

I just type following command:

 

 

$ mkdir sample1
$ cd sample1
$ git init
$ code -r .
$ cd ..
$ mkdir sample2
$ cd sample2
$ git init
$ code --add .

 

 

vscode.gif

What's a useful feature!!

3 Comments

Thanks for the Tip KazukiOta :cool:

Occasional Visitor

Have been thinking if this existed for quite some time. Amazing, thanks for sharing!

Occasional Visitor

Good tip, very helpful.

Is there a way to point Code at the directory of the current buffer w/o closing any buffers?

If I am editing Microsoft.PowerShell_profile.ps1, I'd like to be able to open the containing directory in the sidebar.

That is, navigate to:

~\Documents\WindowsPowershell

in the Terminal pane, and bring that folder in to Code.

If I type

code . -r

It opens the folder in the sidebar, but closes all already-open documents.

Version history
Last update:
‎Sep 12 2019 10:21 PM
Updated by: