WebStorm 2019.1 Help

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.

WebStorm finds and replaces fragments of source code, based on the search templates that you create and conditions you apply.

To find and replace source code structurally

  1. On the main menu, choose Edit | Find | Search Structurally, or Edit | Find | Replace Structurally.

  2. In the dialog that opens, define the search template.

  3. In case of the structural replace, specify the replacement pattern, and define variable constraints as required.

  4. Specify the search and replace options, in particular, the number of occurrences to be matched, and the type of files to be analyzed.

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

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

  1. In the Structural Search dialog (Edit | Find | Search Structurally), create a new search template or use the existing one.

  2. To export a template, click the Settings button 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 the Settings button 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.

Last modified: 16 May 2019