When I open VS Code Diff from the command line using vscode diff file1 ../other-project/file2
, then press CTRL + P
, the diffed file from the other project shows up in my recently opened files.
Is there a way to prevent this from happening? This is confusing, especially because these files have the same names.
Is it possible to hide all files from CTRL + P that are outside of the project folder?
A link to the new feature request (support with thumbs up 👍): https://github.com/microsoft/vscode/issues/201541
2
Answers
I’m not aware of there being a way to achieve this.
I mean, you can manually click the "x" button to make them be forgotten, but I don’t think that’ll satisfy you. You can also disable recent files entirely using the
search.quickOpen.includeHistory
setting (also a bad workaround).The closest thing I’ve seen to this potentially becoming a thing is the feature request Option to not add files to recent history for files outside of the opened folder #98428, which gained some community support, but didn’t get enough in time to get added to the backlog. As an aside, the user who raised that issue ticket got the idea that it’s not okay to go about soliciting support in various dev communities, which I don’t think is true (and I actually suggest people to do). It should be fine for you to raise this again as a feature-request.
The asker of the question has now raised a feature request issue ticket at Hide all files outside the project folder from CTRL + P (Go to file..)’s recently opened in VS Code #201541.
As for workarounds, I can’t think of any robust ones. The
search.exclude
setting applies to history in Quick Open (courtesy of #6502), but I can’t get an exclude-then-include-subset hack to work like is the case for How can I prevent VS Code from changing files that do not belong to the workspace?. There’s another feature-request Add a setting to exclude files/folders from quick open history#157395, but that’s the same schema as
search.exclude
, so I doubt it’d be usable for this use-case either.I discovered a possible (but not very robust) workaround being inspired by Kafiger’s answer post: You can make VS Code "forget" from recently opened files from elsewhere under a common ancestor directory of the workspace folder by putting a pattern like
**/<common-ancestor-directory>/**/*
insearch.exclude
(both user or workplace settings.json work). It surprised me that this works, since I’d have expected it to cause VS Code to exclude everything under the workspace folder from search as well, but for some reason it doesn’t unless you use the root directory / drive root as that common ancestor directory (like/**/*
. don’t ask me why- I don’t know, and am too lazy to go digging in the source code for this). For example, since I put all my projects under my user home directory, I would use the following:For handling files that aren’t under a common ancestor directory that isn’t the root directory / drive root, you can still do similarly I think: just add similar exclusion patterns for the highest ancestor directory(ies) (that isn’t the root directory / drive root) of said file(s).
Note that you might need to either reload VS Code after making that change, or toggle to
false
, save, and then toggle totrue
, and save again.The reason it’s not robust is because if you have a subdirectory under your workspace folder named the same thing as one of those ancestor directories that you want files inside it to show up in Quick Open, they won’t, and I can’t figure out a way to un-exclude that.
As far as I now, there’s no built-in setting to completely hide external files from CTRL + P,
Open File > Preferences > Settings (or press Ctrl+,).
Search for "files.exclude" and expand the setting.
Add the path to the external project folder you want to exclude, using a glob pattern. For example:
Hope this helps.