Search code examples
searchvisual-studio-codefile-type

How to search a string in a specific file type in VSCode?


It should be quite simple, but sometimes I found that searches in VSCode do not work as expected.

In this below example, I just want to search the string stat in all the JavaScript files in the folder ./ocean-data-qc/ocean_data_qc_js. But, in the search results, I get files of all kind of types:

enter image description here

I also want to search in the subfolders files.

Am I doing anything wrong?


Solution

  • With the expression ./ocean-data-qc/ocean_data_qc_js,*.js it will search across all the files of the path ./ocean-data-qc/ocean_data_qc_js and then it will search on all the js files of the project. The result will be the union of both searches

    Instead, the pattern should be ./ocean-data-qc/ocean_data_qc_js/**/*.js to make just one search in all the js files in the folder and subfolders. But it is not working as expected because the files in the .gitignore are included in the search. So, in some way, the pattern in the include section is overriding the excluded paths.

    I have found an issue to answer why the .gitignore is not taken into account in that case. As I am working in multiroot mode, I found two solutions that work:

    • Just using the root folder of the project where I am searching: ./ocean-data-qc/**/*.js. Like this .gitignore is taken into account.
    • The other alternative is to use the search.exclude attribute in the VScode settings.

    Note: The important sections in the VSCode docs: Multiroot search. Advanced search options