470
votes

Is there a way to search for text in all files in a directory using VS Code?

I.e., if I type find this in my search, it will search through all the files in the current directory and return the files that matched.

16

16 Answers

514
votes

You can do Edit, Find in Files (or Ctrl+Shift+F - default key binding, Cmd+Shift+F on MacOS) to search the Currently open Folder.

There is an ellipsis on the dialog where you can include/exclude files, and options in the search box for matching case/word and using Regex.

372
votes

In VS Code...

  1. Go to Explorer (Ctrl + Shift + E)
  2. Right click on your favorite folder
  3. Select "Find in folder"

The search query will be prefilled with the path under "files to include".

52
votes
  • Press Ctrl + Shift + F

    enter image description here

  • Click on 3 dots under search box.

  • Type your query in search box

  • Type ./FOLDERNAME in files to include box and click Enter

Alternative way to this is, Right click on folder and select Find in Folder

16
votes

Ctrl + P (Win, Linux), Cmd + P (Mac) – Quick open, Go to file

16
votes

What is NOT so obvious is that you can use the following pattern to recursively search

./src/**/*.html

so perhaps leave the following as the default for most of your typical searches to remind that there is such a thing

./src/**/

For example I was after an attribute for left-right justify/docking content, I could not remember except "start" so I did the following search which reveals to me "item-start"

enter image description here

This fixed my layout to enter image description here

Instead of enter image description here

Here is where "item-sart" goes in the template. enter image description here

11
votes

I think these official guide should work for your case.

VS Code allows you to quickly search over all files in the currently-opened folder. Press Ctrl+Shift+F and enter in your search term. Search results are grouped into files containing the search term, with an indication of the hits in each file and its location. Expand a file to see a preview of all of the hits within that file. Then single-click on one of the hits to view it in the editor.

11
votes

This action is not bound to a key by default, to bind it do this:

  1. File > Preferences > Keyboard Shortcuts (Ctrl+K, Ctrl+S)
  2. Search for "find folder"
  3. Press the + icon on the left of "filesExplorer.findInFolder" search result
  4. Enter your desired key combination
10
votes

A simple answer is to click the magnifying glass on the left side bar

10
votes

To add to the above, if you want to search within the selected folder, right click on the folder and click "Find in Folder" or default key binding:

Alt+Shift+F

As already mentioned, to search all folders in your project, click Edit > "Find in Files" or:

Ctrl+Shift+F

5
votes

If you have a directory open in VSCode, and want to search a subdirectory, then either:

  • ctrl-shift-F then in the files to include field enter the path with a leading ./,

or

  • ctrl-shift-E to open the Explorer, right click the directory you want to search, and select the Find in Folder... option.
5
votes

And by the way for you fellow googlers for selecting multiple folders in the search input you separate your directories with a comma. Works both for exclude and include

Example: ./src/public/,src/components/

3
votes
  1. Enter Search Keyword in search (CTRL + SHIFT + F)

  2. Exclude unwanted folder's/files by using exclude option (!)

    ex: !Folder/File*

  3. Hit Enter

Search results gives you desired result

3
votes

In order to search only in one folder, you have to click on it and press Alt + Shift + F.

When you use Ctrl, VS Code looks in all project.

1
votes

Select your folder, Press + + F Don't know about windows but this works for mac :)

0
votes

Search across files - Press Ctrl+Shift+F

Find - Press Ctrl+F

Find and Replace - Ctrl+H

For basic editing options follow this link - https://code.visualstudio.com/docs/editor/codebasics

Note : For mac the Ctrl represents the command button

0
votes

Just in case you wanted to use PowerShell to search for and then open all text files in your current directory:

foreach($file in $(dir -recurse -include *.txt))
{
    code $file
}

You could also be a little more specific or even change the file type:

foreach($file in $(dir <specificDir> -recurse -include *.<anyExtension>))
{
    code $file
}