I want to do a custom research inside my code in VsCode. For example: I want to search for the word 'SetState' inside 'useEffect'. Is there a method to do this kind of search?
Is there any plugin or method to do so?
I am trying to look for UseState inside useEffect in my Typescript code. I know how to find each one individually, but together, couldn't figure out
CodePudding user response:
In the two input boxes below the search box, you can enter patterns to include or exclude from the search. If you enter example, that will match every folder and file named example in the workspace. If you enter ./example, that will match the folder example/ at the top level of your workspace. Use , to separate multiple patterns. Paths must use forward slashes. You can also use glob syntax:
* to match zero or more characters in a path segment
? to match on one character in a path segment
** to match any number of path segments, including none
{} to group conditions (for example {**/*.html,**/*.txt} matches all HTML and text files)
[] to declare a range of characters to match (example.[0-9] to match on example.0, example.1, …)
[!...] to negate a range of characters to match (example.[!0-9] to match on example.a, example.b, but not example.0)
VS Code excludes some folders by default to reduce the number of search results that you are not interested in (for example: node_modules). Open settings to change these rules under the files.exclude and search.exclude section.
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.
Also note the Use Exclude Settings and Ignore Files toggle button in the files to exclude box. The toggle determines whether to exclude files that are ignored by your .gitignore files and/or matched by your files.exclude and search.exclude settings.
CodePudding user response:
If you want to search only within a specific file or directory, look at Shub's answer. If you want to search for complex text, you can use regex search by clicking on the .*
icon next to the search bar.
Regex is complicated to learn, but https://regex101.com/ has really good explanations on how things are working, so just try it out.
If you are looking for the text "UseState" inside a function called "useEffect", you could use something like this to search:
useEffect(.*\n)*.*UseState
See this example in action: https://regex101.com/r/gTsuLb/1
Note that this will probably not work when there are multiple calls to UseState
within the same useEffect
code.