Can i have multiple workspaces in VSCode? - visual-studio-code

So I want to have multiple workspaces in the same VScode window, one for work and one for personal projects. Currently I have two workspaces saved:
work.code-workspace,
personal.code-workspace
Whenever i click one of the above workspaces, it'll open a new VScode window. I want to have both the workspaces in one window so i can switch between them easily.
The reason I don't want to have my personal project directory/folder in the same workspace as my work is because it uses a different virtual environment and different versions of frameworks. For eg: in my personal projects file I have from flask import Flask, if I have this file in the same workspace as my work then it'll give me the import flask could not be resolved from source pylance error. But when I try it in a different workspace, the import works fine even though I use flask at work as well.

I frequently use different workspaces for different code-bases (projects) at work. File/Open Recent/... generally gives you a list of recently opened workspaces.

The vscode-workspace-switcher extension adds commands for opening a workspace in the current window or a new window, along with corresponding keybindings.

Related

How to prevent VSCode from changing files that do not belong to the project?

Assume I am working on a project folder my_project while using Python. I want to make sure, VS Code does not allow me to change files that do not belong to the project (they are outside my_project folder).
Example scenario: Once I was debugging a code in Python, I ended up in a file that belonged to my virtual environment and by mistake I pressed a key somewhere. This caused everything crashes afterward and was hard to catch (note it does not show in git status). If I would do the same thing on PyCharm it would show a pop up window warning me. Is the same thing possible for VS Code?

How can I create a local configs for Neovim extending the global init.vim?

Suppose that I have a map on my init.vim that I want to change the behaviour depending on the folder that I am. How could you do that?
A more concrete example: I have a map on my F12 that runs the project that I am. So if I am on a python project, this F12 will run an ipython on a floaternew window, with the current file already imported. Though, if I am on a cpp project, the same F12 will build using Make and running the binary on a floaternew window as well.
Nowadays, I have these two behaviours mapped on different key bindings. But It is going to very nice if I have only one binding to "run the project". Even if I need to open neovim with some parameter in each project, like neovim --local-config mylocalconfig.vim (extending init.vim with some behaviour)
I am kind inspired by a behaviour like direnv but with .vim files.
Any ideas?
There is an option in vim set exrc which enables reading vim config files from current directory, it also works in neovim.
From docs (:h exrc)
Enables the reading of .vimrc, .exrc and .gvimrc in the current
directory. If you switch this option on you should also consider
setting the 'secure' option (see |initialization|). Using a local
.exrc, .vimrc or .gvimrc is a potential security leak, use with care!
also see |.vimrc| and |gui-init|.
This option cannot be set from a |modeline| or in the |sandbox|, for
security reasons.

Multiple configurations for VSCode

At the moment I'm working on a few projects at the same time using VSCode, one in react, another in angular and some good old javascript.
The problem is that I have a few extensions installed that conflict, for example, some code snippets that are the same for React and Angular.
Is it possible to have 3 visual studio code installed on a Mac with different extensions installed?
There are two options for such setup:
Portable installation - unzip VSCode in a folder and create a subfolder there called data. This will trigger the portable mode and all settings will be stored in that data folder. The downside is that you'll have to manually update every portable folder whenever new version comes out. More info here.
Custom config paths - create a shortcut for your VSCode installation, and add those parameters:
--user-data-dir <some-path> --extensions-dir <some-path>
You can put them wherever and have as much shortcuts as you want, they even run in parallel. Best part is once you update the installation, all the configs are upgraded too. More info here.
Both modes are incompatible, so you have to choose one.

Open the same directory twice

On command line, I could open a directory like:
code .
Now, I want two of the identical diretory opened and displayed in another window.
(It's not spliting the editor)
Then, I tried again.
code .
Nothing happened.
There's still one directory opened.
How to achieve such a task?
You can do this with the following ways:
1- Manually open a new window (ctrlshiftn) and go to:
File > Add folder to Workspace. Then just select the folder.
2- Open the command panel (ctrlshiftp) enter dupl and hit enter that will duplicate the current workspace in a new window
*dupl is just a filter for the complete command that is: Workspaces: Duplicate Workspace in New Window thanks to dipnlink comment
Source: https://code.visualstudio.com/docs/editor/multi-root-workspaces
*Done in windows (10), vscode (1.35.1)
In the latest version, it is actually much simpler.
In a window of the project you want to duplicate, open the command panel (Command + Shift + P in Mac or Ctrl + Shift + P in Ubuntu), then type dupl (and select Workspaces: Duplicate As Workspace in New Window), this will duplicate your workspace in a new window. Now you can have 2 windows of the same project at the same time.
click
file > duplicate workspace
Click Add workspace folder... and open the same folder. Works for me, other solution doesn't work, just jump focus to another window.
As far as I know, the accepted answer is not correct as C14L indicates.
It can be done by opening a different folder that includes the folder you're working in. So say we have /project and /project/src and /project/build, you're probably interested in having src open in two instances of VSCode, which you can achieve by opening /project and /project/src.
In addition to accepted answer, here's the trick if you want to open same project in two different windows but showing two different git branches:
Copy the project folder and open that folder!
If you want two windows in two different git branches then this simple trick works. I don't know of any other solutions.
The accepted answer works, but I don't really like the fact that the folder is opened into an unnamed workspace, and upon closing window, we will be prompted to save that workspace. I am expecting more like Sublime Text like behavior.
Luckily there is VSCodium, VSCode's twin/clone without telemetry to Microsoft. So I ended up opening the folder once in either VSCode or VSCodium, then a second time in the other. This so far worked quite well for me.
I wanted to do this for working in two branches side by side and then I realized it was not possible because you cannot have two active branches in exact same git repo folder.
So, if you are looking to do the same, you should instead just make a copy of a folder and switch to another branch there. Options described in other answers will not work for this scenario due to fundamental way git works.

Eclipse cannot save python2.7 interpretor

Though this is strange but happening with me. I add python3.2 in in the Pydev> interpreter-python it is saved for always. I can run my scripts pretty well. But when I add a 'python2.7' in the Pydev> interpreter-python it shows there till preferences window is open and once I close the preferences window it disappears and takes other interpreters with it. I mean an empty 'interpreter-python' setting.
I save my workspace in dropbox so that I can use share my settings on different systems both using Ubuntu 12.04 X64. I am sure it is not a Dropbox ACL setting issue as 'Python3.2' settings save and work pretty well until I add 'python2.7' which removes all the interpreters including itself.
Please Help. Unable to code.
AK