How to open directory from terminal in vs code? but inside the same window - visual-studio-code

I have vs code open and I'm using bash terminal within it, when I'm inside the directory I want to open I type code . and that opens everything I want but it opens a new vs code window. Is there a way it can open inside of the current vs code window I am in?

Try code . -r to force opening in the same window. See https://code.visualstudio.com/docs/editor/command-line#_core-cli-options for more options in the command line.
For a more "permanent" solution there is this setting:
Window: Open Files In New Window
Controls whether files should open in a new window. Note that there
can still be cases where this setting is ignored (e.g. when using the
--new-window or --reuse-window command line option).
Set it to off and then ``code .` is enough.

Related

Is it possible to quickly swap workspaces using the integrated terminal in Visual Studio Code?

I would like to make it so that when I'm traversing directories using the integrated terminal, running code . opens the current working directory in the integrated terminal within the current VSCode window, "discarding"/closing the currently opened workspace, instead of opening a new window for that folder. Is this possible? If not, what would be a similar solution?
You can use code -r .
code --help gives the following description:
-r --reuse-window Force to open a file or folder in an already opened window.
Another source is Visual Studio Code Tips and Tricks
As #ltomase found in their answer (and exanding on their answer), you can use the -r option of the code command. The doc comment for this option in the --help menu says this:
Force to open a file or folder in an already opened window.
There are other approaches not involving the command-line:
Open command palette and use the File: Open Workspace from File... command to open workspace files (.code-workspace), or
Open command palette and use the File: Open Folder... command to open folders (keyboard shortcut: ctrl+K , ctrl+o).
Use alt+f to open the File menu, then use keyboard navigation to go to "Open Recent" and then select a recent workspace to open.

How do you select the terminal location for every terminal type in a VS Code workspace?

I am working in a VS Code workspace with multiple directories. When I open the default terminal (Powershell) it get a prompt asking which of the directory roots I want to open the terminal in.
However, if I open another terminal from the dropdown, it opens at the root location of whichever file that I am currently displaying.
Is there a setting to show this prompt for every new terminal, not just the default one? Specifically for the WSL terminal.

Open file from integrated terminal in VS Code

I have VS Code setup with WSL on my Windows 10 machine. I am trying to find the command I can use to open an existing file from the integrated terminal in the current VS Code window.
I tried code filename, which launches a new VS Code window. I tried with code -r filename, but it also launches a new window.
Is there a way to quickly open a file when I'm focussed on the terminal?
As of version 1.43.1, this appears to now work as expected, without additional add ons.

Open a file in VS code using `open -r`

I was trying to use the command code -r file_name.py in the integrated terminal in VS code to open the file in the existing window that I'd already opened. However, another new VS code window was still generated. What's weird is that originally, I could open a file by simply using code file_name.py without using the -r flag. Is there any way to solve the problem? I want the file to be opened in a new tab in the same window instead of in a new window. Any experience shared will be appreciated!
When using VS code the correct command to open a file in an existing code window is indeed code -r .\file_name.py, if you are doing so from a terminal within VSCode it will do so within that instance of VSCode.
My instance of VSCode defaults to using CMD on Windows 10 for this command. What are you using to run this command?

How to open file in VSCode from integrated terminal in a current application window?

Now:
rudskoy$>: code temp.py
—————> It opens temp.py in a new VS Code window!
What I want:
rudskoy$>: code temp.py
—————> It opens temp.py in a current window as a new tab
Is this behaviour configurable?
I've investigate that terminal command (code) has an --help option.
--help says that: -r, --reuse-window Force opening a file or folder in the last active window.
This -r option is that I want to get from my question.