0

Is it possible to exclude test files when doing a grep search in VS Code?

I would have thought one of these regexes would have worked ^/(?!Test$)[a-z0-9]+$ Or ^/(?!Test)([a-z0-9]+)$

1 Answer 1

2

Search in VS Code doesn't utilize regex in excluding files (see open issue). It is configured with glob patterns. So you can still do the following:

  • files to exclude: *Test.cls

This, of course, assumes your test classes are named with test at the end (ex. MyControllerTest.cls). If it's in the front just flip that around

  • files to exclude: Test*.cls

Likewise, you can include multiple paths to exclude to cover different permutations by separating them with a comma:

  • files to exclude: *test.cls, *Test.cls, Test*.cls

enter image description here

If you don't want to specify each time, you can edit your workspace/user settings (File --> Preferences --> Settings)

enter image description here

As the documentation notes, excluding a file pattern in the settings has a slight difference than directly in the search.

Note that glob patterns in the search view work differently than in settings such as files.exclude and search.exclude. In the settings, you must use **/example to match a folder named example in subfolder folder1/example in your workspace. In the search view, the ** prefix is assumed. The glob patterns in these settings are always evaluated relative to the path of the workspace folder.

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.