70

Although this is not a direct dev question, but it does relate to a dev tool, which is very related to my development work:

When I search for a file in VSCode (CTRL+P), I see that it doesn't include files and folders that are a part of the .gitignore file.

I can very well see the logic in that, and that's fine, but how can I disable this (default?) behavior? Meaning, I do want this search to include ALL files in the project, regardless to the .gitignore file (or any other ignore file, for that matter).

4 Answers 4

100

Open visual studio code settings (cmd+ , on Mac or Ctrl+,), search for the setting:

Search: Use Ignore Files

and untick the checkbox

enter image description here

8
  • 4
    Is there any way to do this for a single search? As in, don't use the setting to control whether .gitignore'd files are ignored, just prefix the search with something like all . . .. I realize this is a longshot.
    – Drew2
    Aug 18, 2020 at 17:19
  • 10
    You can toggle the "Use Exclude Settings and Ignore Files" when performing a search: user-images.githubusercontent.com/323878/…
    – gbalduzzi
    Jan 18, 2021 at 16:53
  • 3
    Don't know why it doesn't work for all those mentioned under .gitignore for me. Feb 10, 2021 at 19:03
  • 1
    is there a way to include a certain directory while ignoring all other files
    – Esqarrouth
    Mar 5, 2021 at 14:09
  • @gbalduzzi Luckily, this also affects Ctrl-p/Ctrl-e search. Where there're no any tweakable controls.
    – Onkeltem
    Jan 24, 2022 at 5:50
26

As the screenshot in this answer shows, vscode uses rules in both .gitignore and .ignore. Since Git only recognizes .gitignore, we can negate some rules in .ignore to bring them back in the vscode search result.

A demo:

.gitignore

.env.local

.ignore

!.env.local

This trick also works for tools like rg and fd.

2
  • 3
    This was the only way I found to get the ctrl-p (cmd-p) search to include git-ignored files. Thank you Feb 16 at 15:47
  • This is clever!!
    – towry
    Jul 11 at 15:12
4

Don't know if this was still useful but one way I found out is. There was a search.exclude setting in the config option

Nornally we would use it to exclude pattern by set it to true. However, we could force the inclusion of excluded pattern by setting the rule as false

{
    "files.exclude": {
        "**/*.asset":true,
        "**/*.mat":true,
        "**/*.meta":true,
        "**/*.prefab":true,
        "**/*.unity":true,
    },
    "search.exclude": {
        "**/*.asset":false,
        "**/*.mat":false,
        "**/*.meta":false,
        "**/*.prefab":false,
        "**/*.unity":false,
    }
}

This is my setting for unity project and this was made all the meta files that was ignored missing from explorer. But I still be able to searching its content

-2

Make sure that your working directory is an actual Git repository.

VSCode doesn’t skip paths from .gitignore if you didn’t perform git init or git clone in the first place.

1
  • This answer is false, VS Code does use .gitignore to ignore files unless you have those files already open in tabs. Feb 2 at 10:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.