Structural Search and Replace
A conventional search process does not include the syntax and semantics of the source code. Even if you use regular expressions, WebStorm still treats your code as a regular text. The structural search and replace (SSR) actions let you search for a particular code pattern or grammatical construct in your code considering your code structure.
To find and replace source code structurally
On the main menu, choose, or .
In the dialog that opens, define the search template.
In case of the structural replace, specify the replacement pattern, and define variable constraints as required.
Specify the search and replace options, in particular, the number of occurrences to be matched, and the type of files to be analyzed.
Specify the scope to perform the structural search and replace in. To do that, click the down arrow in the Scope list, and select one of the pre-defined scopes, or click the ellipsis button, and configure the desired scope in the Scopes dialog.
Click Find. The detected occurrences are displayed in the Find tool window.
Note that in case of replacement, you can select the desired matches in the search results and click the Preview Replacement button. The corresponding occurrence is highlighted in the source code.
Share search templates
You can share a search template with your peers by exporting or importing it.
In the Structural Search dialog ( ), create a new search template or use the existing one.
To export a template, click and select Export Template to Clipboard. WebStorm adds the XML representation of the template to a clipboard (press Ctrl+Shift+V to see the clipboard's content). You can share this representation with other developers in chat, email, or a forum.
To import a template, copy (Ctrl+C) the shared XML code from anywhere (email, chat, or a forum) and in the Structural Search dialog, click and select Import Template from Clipboard. WebStorm takes the XML code representation and converts it into a template including variables and a scope if it is present.