Home > front end >  How to prevent VS Code remembering files outside work folder?
How to prevent VS Code remembering files outside work folder?

Time:10-10

My workflow with VS Code is to always use project folders on projects. This works great, but there's one thing that's messing things up right now;

When opening just a single file from another project while working in another project, lets's say webpack.config.js, I use Windows Explorer rightclick to open that file in VS Code. However, this always opens the file in the currently open VS Code instance.

This adds the file from that other folder now to the memory of the previously opened files in the open project while it has nothing to do with that project.

When using the quick file open of VS Code now it happens a lot VS Code opens a file from that other folder, only because that outside file has been opened once while I was working on this project.

This is error prone as now it happens a lot, especially when working fast, that the wrong, for instance, package.json or webpack.config.js file gets opened, because VS Code now also suggests files that are outside this project. That's pretty frustrating and causes changes to be made in the wrong files pretty quickly.

I know we can clear the editor history and have to do it a lot now. But to me that's the other way around, doesn't solve the real problem and when not done often the issue remains.

So I want to get rid of this issue and have the following questions:

1) How can we change the 'Open with Code' rightclick menuitem in Explorer to open files always in a new instance of VS Code? 2) Is there a config settings to disable the behaviour that VS Code remembers files that are outside of the current work folder?

Thanks in advance, this thing is bothering me for quite some time now!

CodePudding user response:

How can we change the 'Open with Code' rightclick menuitem in Explorer to open files always in a new instance of VS Code?

I assume you are a Windows user. You can edit the context menu behavior from Regedit.

Follow the below steps:

  • Press Windows R
  • Type regedit and press OK
  • Go to Computer\HKEY_CLASSES_ROOT\*\shell\VSCode\command in regedit
  • Add -n parameter to the command like below

regedit

It will help you to open every file in a new window when you use Open with Code.

For your second question, Is there a config settings to disable the behavior that VS Code remembers files that are outside of the current work folder?

  • Open VS Code settings
  • Search window.openFilesInNewWindow
  • Make it off to on like below

vscode

With this configuration, you can't open new files in the current workspace therefore technically you prevent VS Code remember outside files. Not directly but it helps.

  • Related