VS Code - Search for text in all files in a direct

2020-02-16 06:05发布

问题:

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.

回答1:

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.



回答2:

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".



回答3:

Press Ctrl + Shift + F

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



回答4:

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



回答5:

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


回答6:

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.



回答7:

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



回答8:

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



回答9:

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.


回答10:

  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



回答11:

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



回答12:

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/