vs-code: How to open current WSL folder *as wsl* from command line?

Viewed 765

How do I do this in my non-vs-code terminal:

wsl:/home/peter/myproject$ code .

and then have myproject open in Visual Studio Code in a new WSL window or somehow in WSL mode?

I am able to open the current folder as a "normal" windows folder using:

"$(wslpath 'C:\Users\pvm\AppData\Local\Programs\Microsoft VS Code\Code.exe')" .

but then many things don't work, because it isn't opened as a WSL folder. I can however, click on where the red arrow points, and then on where the green arrow points.

code screenshot for reopen folder in wsl

As an alternative, I can open a WSL window in VS Code, and open a terminal from there. From inside this terminal-in-code, I can navigate to a folder and type code .. Then it gets opened exactly as I want, but this is only possible from a terminal-in-code, not from a standalone "normal" WSL terminal. If one tries to run the same code command from a normal terminal, one gets a "Command is only available in WSL or inside a Visual Studio Code terminal." error. And this is as designed.

So the question remains: How do I open a folder from a standalone WSL terminal in VS code in WSL mode?

1 Answers
Related