107

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).

6 Answers 6

156

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

Sign up to request clarification or add additional context in comments.

9 Comments

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.
You can toggle the "Use Exclude Settings and Ignore Files" when performing a search: user-images.githubusercontent.com/323878/…
Don't know why it doesn't work for all those mentioned under .gitignore for me.
is there a way to include a certain directory while ignoring all other files
There will be too many noise to untick the option. Use .ignore to negate specific files.
|
54

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.

3 Comments

This was the only way I found to get the ctrl-p (cmd-p) search to include git-ignored files. Thank you
This is clever!!
This is much better than accepted answer - accepted answer will include all node_modules in search which is obviously not wanted.
12

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

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

1 Comment

you should mention which .json file. I think in your answer you might be talking about modifying .code-workspace file
3

If you want ctrl+P and ctrl+shift+F (Search feature) to function the same, here's the three options I use.

Add this to your .vscode/settings.json file:

{
   "explorer.excludeGitIgnore": false,
   "search.useParentIgnoreFiles": false,
   "search.useIgnoreFiles": false
}

This works well in a project with git submodules where you edit the main repo and the submodules at the same time.

1 Comment

hey, you have to note to put it inside "settings" JSON node not at the settings.json level
0

For an intentionally temporary work around (i.e. so as to avoid altering settings):

Press ctrl + ` to open terminal, then:

code my-ignored-file.txt

that will open the ignored file, and has the little advantage of tab complete (which the Quick Open menu doesn't for ignored files).

Comments

-5

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 Comment

Image
This answer is false, VS Code does use .gitignore to ignore files unless you have those files already open in tabs.

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.