25

How can I search in one subfolder folder of my workspace only?

CTRL+SHIFT+F searches in the whole workspace, and since this is large I get way too many hits in unrelated folders and files.

Jeroen
  • 60,696
  • 40
  • 206
  • 339
El Dude
  • 5,328
  • 11
  • 54
  • 101

4 Answers4

31

Two options:

  • Left-click the folder in the Explorer and use ALT+SHIFT+F
  • Right-click the folder in the Explorer and choose "Find in folder..."

This will give you a slightly changed search bar:

vscode search in folders sidebar

Jeroen
  • 60,696
  • 40
  • 206
  • 339
5

The key combo is ALT+SHIFT+F

p.campbell
  • 98,673
  • 67
  • 256
  • 322
4

Another twist on this is how to search in a collection of named subfolders. For example, consider a directory structure like this:

Project
├── Foo
│   ├── inc
│   │   ├── tom.h
│   │   └── dick.h
│   └── src
│       ├── tom.cpp
|       └── dick.c
├── Bar
│   ├── inc
│   │   └── harry.h
│   └── src
│       └── harry.c

The "files to include" box will accept glob notation, so if the user wants to search only in "src" directories, not in "inc" directories, they can specify:

./**/src/*

This is interpreted (from right to left) as "any file, in a 'src' sub-directory, underneath any directory".

Obviously, this is a trivial example which could be handled by filtering on the file extension, but the principle applies to much more complex searches. For another example, see: https://stackoverflow.com/a/59083215/6419400

Dave C
  • 186
  • 1
  • 3
2

There is a ... under the search box:

search in a specific folder

After clicking on it, you can specify which files you want to include or exclude from your search results.

You can also use wildcards as shown in the placeholder.

For example, if I write this in the files to include field:

repo/*.go

then it will show you all files with .go extension in repo folder.

  • means all

There is also two other ways to open this option (as Jeroen also mentioned):

  • Right-click the folder in the Explorer and choose "Find in Folder..."
  • Left-click the folder in the Explorer and use ALT+SHIFT+F in windows or Option+SHIFT+F in Mac
Arsham Arya
  • 1,461
  • 3
  • 17
  • 25