VSCode highlight PWD in Explorer - visual-studio-code

Contrary to changing the terminal to the present working directory in VSCode, I'm looking for a way to get the present working directory in the focused integrated terminal and then highlight it in the Explorer. One way to do this would be using code ., but that opens up a new workbench if you're in a child directory. Is there a native way or an extension that supports doing this? Both command palette and keyboard shortcuts would work.

So far, I can't find any APIs for:
Reading the CWD from the active terminal.
Changing the selected file in Explorer.
A workaround is to use code ./some-file to open it in the active Explorer.

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.

Why does code not recognize paths in a system shortcut?

I want to use a shortcut to open up a specific folder in Visual Studio Code in a new window. I am on Fedora with Gnome Shell and have tried the integrated shortcut manager that can be found in the settings. When I define a shortcut with the command code -n ~/path/to/folder, Visual Studio opens a new file with the name folder. When I run the same command in the terminal it works as expected, i.e. a new window is opened in the specified folder.
Turns out ~ cannot be used in this context, so providing an absolute path fixed the issue.

In VSCode, how to open local files without using a dialog but just by typing and Tab-complete?

I was so used to the way of opening a file in Emacs, by just C-x C-f and typing and tab-completing, without needing to use a mouse. In VS Code, I have to go through a "open file" system dialogue using a mouse to find my file. But when opening a file in SSH server, VS Code offers a built-in dialogue to find your file, by just typing and auto-complete. Is there a way to use the "open SSH file" dialogue to open local files, or a similar way by just typing and tab complete?
Add the following setting in your JSON config:
"files.simpleDialog.enable": true
This does not open the native file browser for local files. Instead, you can search for them in the same manner as you would do for remote files:

How to change folder that opened by default in VSCode?

I have small problem with VSCode folder, that opened by default.
Problem description: I start new instance of VSCode (trough File->New Window), and then if I choose File->Open Folder it opens dialog with my Windows user folder as starting point (C:\Users\MyUser)
Question: How can I change that folder in settings (if it possible)? So by default it will show as start point for example D:\development\ ?
At the time I write this answer, this is not possible. There are two problems on Windows, and one problem on Mac and Linux:
VS Code does not provide a default path to the file dialog 1. It does remember the last folder that you opened a file in, but that path cannot be used as a default because it is overwritten constantly.
On Windows only, Electron ignores the default path when creating a file dialog if the default path is a directory 2.
An extension also cannot solve this, because extensions are not allowed to modify the File menu 3.
I think the best option at this point is to pin a folder to the Quick Access area in Windows Explorer, as suggested in a comment, or to put an actual shortcut in the user profile folder.
Workspaces and File > Open Recent may also be helpful if you often open the same folders.
Your main problem is that you are unable to open your specific folder in VScode.
To solve that you can simply open the terminal/cmd in that specific window by just typing cmd in your search bar or just by pressing shift+right-click in that folder.
Now your cmd is open and you just have to type "code ." in the cmd and press enter to open the current folder in your VSCode.
In case that code . doesn't work for you then you have to add the Vscode in the environment variables of your windows.
Visual Studio doesn't provide a specific feature to open a specific path. But there is a solution to your problem. You are saying that you want D:\develpment as a default when you open VS Code. You can go to that specific directory or create shortcut to desktop then click right click on that folder and then click on open with code. If you didnot see open with code then reinstall your VS code and check on open with code when you are reinstalling VS Code.
make a shortcut on the desktop for vscode and then modify it and add the folder after the .exe command. This will default open that folder when you double click on it.
Visual Studio Code can be installed in two ways - User setup and System setup. I strongly believe you have User setup installed in your PC. Try re-installing it System-wide. That should probably fix your problem.
For more information: https://code.visualstudio.com/docs/setup/windows#_user-setup-versus-system-setup
PS: A lot more information is needed, you can share a screenshot of the window and elaborate more on it.

Visual Studio Code edit file

When I try to edit a file in visual studio code, I type the command 'code filename.ps1' and the code used to automatically open as a second tab in the editor.
Now, when I do the same thing, it opens in a new window. I have not changed anything in my settings and I can't find an associated Preference that controls this.
Anyone know exactly the default setting that I need to look at?
According to CLI Options this should work:
code -r filename.ps1
>
-r or --reuse-window
Forces opening a file or folder in the last active window.