Ray
Ray

Reputation: 8623

Visual Studio Code search across files (find in files) is not working

I am using Visual Studio Code 1.31.1 in MacOS 10.13.6. I open VSCode, I open a folder of text files, and I press command-option-F, or use Edit -> Find in Files. I search for a string that I know for sure exists in multiple text files in the open folder, and it says it can't find it.

Searching across files works if I have the folder open and have each and every single file open as a tab, which is rather pointless. Is there a way to search across files without actually having them all open as tabs?

I think it was because I opened a folder on Google Drive File Stream. It works fine on local files.

Upvotes: 103

Views: 106299

Answers (20)

Bilal Parray
Bilal Parray

Reputation: 1

If you want VS Code to search inside the android folder while keeping it in .gitignore, follow these steps:

Override .gitignore in VS Code

Open VS Code Settings (Ctrl + , or Cmd + , on macOS).

Search for: "search.useGlobalIgnoreFiles".

Uncheck the option "Use Ignore Files". Now, VS Code will search inside the android folder, even if it's in .gitignore.

Alternative: Disable Ignore Files for One Search

Press Ctrl + Shift + F to open search.

Click the gear icon in the search bar.

Uncheck "Use Exclude Settings and Ignore Files".

This will make the search include ignored files temporarily.

This way, your android folder stays in .gitignore, but VS Code will still search inside it.

Upvotes: -1

RokeJulianLockhart
RokeJulianLockhart

Reputation: 348

Using code-insiders-1.88.0-1710157206.el8.src, I had to:

  1. Manually open each editor (tab):
    1. enter image description here

    2. enter image description here

  2. Reselect the filter:
    1. enter image description here

    2. enter image description here

    3. enter image description here

After that, the list would be populated.

Upvotes: 1

Jonathan
Jonathan

Reputation: 15452

In my case, this was caused by accidentally toggling the "Search only in Open Editors" option.

enter image description here

Upvotes: 211

Rogério Amaral
Rogério Amaral

Reputation: 21

I was facing a similar issue last month, and I was unable to find any solution on the internet. So what I did was that I created a backup of my settings.json (not defaultSettings.json) file and then cleared its contents and restarted VSCode. It worked, the only downside was I had to reconfigure some of my settings though, although it was totally worth it, since this was a big pain in the a** for me.

You can search for settings.json by pressing Control+Shift+P.

Upvotes: 2

sadhruva
sadhruva

Reputation: 29

I had the same issue. I fixed mine by removing files in .gitignore.

Upvotes: 2

Viresh Mathapati
Viresh Mathapati

Reputation: 79

When I tried to search using "Ctrl+F" it didn't search properly and not resulted any output.

Instead I tried "Ctrl+Shift+F" and it did proper search and resulted output.

It's on Win 11, VSCode Version 1.85.1

Upvotes: 1

SL5net
SL5net

Reputation: 2566

In my case, I had to save the file once more. The effect after I searched was visible in the application, also in git diff, but not in the Studio Code search. Not in the full text search and also not in the search in the file. When I saved the file again, the effect was then same everywhere. I did put a space somewhere in this file. Then saved and then removed again. Git diff helped me find the file.

  • Version: 1.81.0
  • Electron: 22.3.18
  • OS: Linux x64 6.2.0-26-generic

Upvotes: 1

JGFMK
JGFMK

Reputation: 8904

I was using VS Code 1.79.2 on a Windows Server OS and editing some Python and experienced a similar reduction in the number of results found. It turned out Find in Selection icon in search text overlay was highlighted. Tried to print it but tooltip would then disappear - so improvised and overlaid some text on image.. See below enter image description here

Upvotes: 1

peractio
peractio

Reputation: 633

The problem for me was that the files were found in directories listed in .gitignore, and the search excluded files from .gitignore.

While some other answers/comments mentioned this, I thought it made sense to compile the options in a clear answer. You have a few options:

  1. Turn off "Use Exclude Settings and Ignore Files" on the bottom right corner of the search feature. This affects the particular search, and is recommended if you want to be flexible: enter image description here
  2. Uncheck "Search: Use Ignore Files" in the settings (and potentially "Search: Use Global Ignore Files" too). This affects your settings, rather than just this search. You could do this for your user or workspace settings, if you'll consistently want to exclude the ignore files: enter image description here
  3. Remove the file/folder from .gitignore (not recommended, since you put it in the .gitignore file for a reason)

Note: I was connecting to a remote server with VSCode.

Upvotes: 7

user2138149
user2138149

Reputation: 17384

I initially wrote this answer describing a confusing "inverted" behavior of the Search only in Open Editors option/button.

However, after playing around it turns out that what the GUI was showing was not "in sync" with what the search results were returning. Toggling the options a few times appears to have fixed things.

So if your search doesn't appear to be returning any results, I would suggest toggling the Search only in Open Editors and Use Exclude Settings and Ignored Files options.

Otherwise, for information, here is my previous answer:


VS Code has an extremely confusing "inverted" interface when it comes to the option Search only in Open Editors.

There is also another option which affects how search works in a confusing way: Use Exclude Settings and Ignored Files.

The below screenshot shows both:

VS Code Search Options

Note that:

  • Search only in Open Editors is OFF
  • Use Exclude Settings and Ignored Files is ON

With these options I get search results back, with them set the other way around - confusingly - I get nothing.

Important to note:

  • If you turn Use Exclude Settings and Ignored Files OFF, then VS Code seems to stop searching any files, EXCEPT for those which are currently open in tabs. This is very confusing and not the behavior one would expect. The expected behavior would probably be to search the whole opened Folder/Workspace by default.

  • If you turn Search only in Open Editors OFF, then only open editors will be searched. This is the "inverted" behavior. My current build of VS Code has the indicator "inverted" for this GUI element. When it looks like it is in the "ON" state, it is actually "OFF". When it looks like it is in the "OFF" state, it is actually "ON'.

  • These two things interact in unexpected ways: (This is the behaviour I observed after toggling both buttons a few times. It is different to what I was seeing a few minutes ago.)

  • Open Editors (looks like) it is OFF, Use Exclude Settings (looks like) it is ON, search appears to search whole workspace.

  • Open Editors (looks like) it is OFF, Use Exclude Settings (looks like) it is OFF, search appears to search open tabs only.

  • Open Editors (looks like) it is ON, Use Exclude Settings (looks like) it is OFF, search appears to search whole workspace.

  • Open Editors (looks like) it is ON, Use Exclude Settings (looks like) it is ON, search appears to search whole workspace.

I suspect that when typing / editing the search terms, replace option, and files to include/exclude options, VS Code does not check the state of the option buttons before performing the search. This is likely the source of the bug I was seeing earlier.

Upvotes: 3

elirandav
elirandav

Reputation: 2073

In my case, it was files with no extensions I was not able to find. Once I added those files an extension, I was able to find them via the search feature.

Upvotes: 1

Jonas Braga
Jonas Braga

Reputation: 635

It could be that the search is looking into all folders (including node_modules ones), so as it is too big, the search never ends

To fix that, you can list all folders that you want to exclude of the search, to do that, open your vscode settings (ctrl + ,) type "Search: Exclude" in the search box and add your folders. (Btw some are already added by default)

Besides, remember to enable that filter in your search, this is simple, just toggle on the gear button in your search section

Exclude button search

If you are still not sure about what to do, take a look in this briefly gif

Exemple setting things up

Upvotes: 25

JDseca
JDseca

Reputation: 111

I had an issue with searching in a project with git submodules and found that the gitlens add-on defaults to ignore searching any submodules:

enter image description here

Setting this to 2 or more may address your problem.

Upvotes: 3

Pankaj Ithape
Pankaj Ithape

Reputation: 51

Go to settings, search "Search" , there will be list to exclude folders. Remove item which might be accidentally got included, which might causing search item in all directory is not working.

enter image description here

Upvotes: 5

BoboStriker
BoboStriker

Reputation: 31

I just had this problem on VS Code 1.58.2 / Mac OS 10.15.7

None of the above solutions worked for me, it still keeps saying 'No results found in open editors' no matter what I do.

But I did get it working by changing the 'Search: Mode' in the settings (for the workspace, or any other scope if needed) from 'view' to 'reuseEditor'.

Yes, this doesn't fix it if you really want the results in the Explorer tab rather than a completely new editor window, but it works.

Upvotes: 2

Armend Ukehaxhaj
Armend Ukehaxhaj

Reputation: 657

Had this same issue, the search functionality was only working for files that were open in the editor. My issue was that VS Code had an update downloaded and ready to update, so I just restarted VS Code, let the update finish and the issue was gone.

Upvotes: 19

KaseyMK
KaseyMK

Reputation: 33

In my case, I had somehow gotten my Explorer set on a subfolder of my project. Closing VS Code and reopening the workspace reset everything and search worked again.

Upvotes: 1

hahuaz
hahuaz

Reputation: 403

Check out your vs code settings. It excludes some folders by default e.g. node modules.

Upvotes: 7

Frank Ali
Frank Ali

Reputation: 251

I had this problem today. Turns out I had a deprecated setting for advanced RegEx searches "search.usePCRE2": true, Once removed, search started working as expected.

Upvotes: 2

NickBluePowder
NickBluePowder

Reputation: 130

Had the same issue on Mac, seems like it was related to Google Drive. once I moved the files on my local drive the search worked fine.

Upvotes: 9

Related Questions