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. Basically like if I did a grep. My coworker told me Sublime has something like this.
This question is related to
visual-studio-code
Ctrl + P (Win, Linux), Cmd + P (Mac) – Quick open, Go to file
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
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
A simple answer is to click the magnifying glass on the left side bar
If you have a directory open in VSCode, and want to search a subdirectory, then either:
files to include
field enter the path with a leading ./
,or
Find in Folder...
option.In VS Code...
The search query will be prefilled with the path under "files to include".
This action is not bound to a key by default, to bind it do this:
Enter Search Keyword in search (CTRL + SHIFT + F)
Exclude unwanted folder's/files by using exclude option (!)
ex: !Folder/File*
Hit Enter
Search results gives you desired result
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"
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.
Select your folder, Press ? + ? + F Don't know about windows but this works for mac :)
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/
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.
Source: Stackoverflow.com