WebStorm 8.0.0 Web Help

The standard facility helps you find and replace text strings in the active editor.

In this section:

To find a text string in the current file
  1. On the main menu, choose Edit | Find | Find, or press Ctrl+F or Alt+F3Ctrl+F or Shift+Alt+3Ctrl+F or Shift+Alt+3Ctrl+F or Alt+F3Ctrl+Alt+S, Alt+F3 or Ctrl+SCtrl+F or Alt+F3Ctrl+F or Alt+F3Ctrl+F or Alt+F3Command FCommand F or Alt F3Command F. The search pane appears on top of the active editor.
  2. If necessary, specify the search options.
  3. In the search field, start typing the search string:

    img

    As you type, the first occurrence of the search string after the current cursor position is selected; the other occurrences are highlighted in the editor. In addition, the matching occurrences are marked in the right gutter with stripes.

    img

  4. Explore search results.
To replace a text string in the current file
  1. On the main menu, choose Edit | Find | Replace, or press Ctrl+RCtrl+RCtrl+RCtrl+RShift+Alt+5Ctrl+HCtrl+HCtrl+FCommand RCommand RCommand R. The search and replace pane appears on top of the active editor.
  2. If necessary, specify the search and replace options.
  3. In the search field, start typing the search string. As you type, the matching occurrences are highlighted in the editor, and a Replace pop-up dialog box opens at the first occurrence, suggesting you to replace the current occurrence, or all of them, with an empty string.
  4. Start typing the replacement string.
  5. Explore search results, and, using the buttons of the replace dialog box, replace occurrences as required. See Search and replace options below.
Working with search results
  • To initiate a new search, do one of the following (depending on the current focus):
    • If the editor has the focus, press Ctrl+F or Alt+F3Ctrl+F or Shift+Alt+3Ctrl+F or Shift+Alt+3Ctrl+F or Alt+F3Ctrl+Alt+S, Alt+F3 or Ctrl+SCtrl+F or Alt+F3Ctrl+F or Alt+F3Ctrl+F or Alt+F3Command FCommand F or Alt F3Command F.
    • If the search field has the focus, press Ctrl+ACtrl+ACtrl+ACtrl+ACtrl+X, HCtrl+ACtrl+ACtrl+ACommand ACommand ACommand A

    In both cases, the existing search string will be selected, and you can start typing a new one.

  • To jump between occurrences, do one if the following:
    • Press Shift+F3 or Ctrl+Shift+LShift+F3 or Ctrl+Shift+LShift+F3 or Ctrl+Shift+LShift+F3 or Ctrl+Shift+LShift+F3, Alt+R or Ctrl+RShift+F3Shift+F3 or Ctrl+Shift+LCtrl+Shift+KShift Command GShift F3 or Control Shift LShift Command K or F3 or Ctrl+LF3 or Ctrl+LF3 or Ctrl+LF3 or Ctrl+LF3 or Alt+SF3F3 or Ctrl+LCtrl+KCommand GF3 or Control LCommand K.
    • Use img or img buttons in the Search pane.
    • Click the gutter stripes.
  • The search pane shows the number of found occurrences. If no matches are found, the search pane is red highlighted:

    findResultsNil

  • Use Code completion in Find and Replace panes. Start typing the search string, press Ctrl+SpaceCtrl+SpaceCtrl+SpaceCtrl+SpaceAlt+SlashCtrl+SpaceCtrl+Space or Ctrl+Back SlashCtrl+SpaceControl SpaceControl SpaceControl Space, and select the appropriate word from the suggestion list.
  • Use the recent history of searches: with the search pane already open, click find1 to show the list of recent entries.
  • With the search or replace pane already opened, use Ctrl+RCtrl+RCtrl+RCtrl+RShift+Alt+5Ctrl+HCtrl+HCtrl+FCommand RCommand RCommand R or Ctrl+F or Alt+F3Ctrl+F or Shift+Alt+3Ctrl+F or Shift+Alt+3Ctrl+F or Alt+F3Ctrl+Alt+S, Alt+F3 or Ctrl+SCtrl+F or Alt+F3Ctrl+F or Alt+F3Ctrl+F or Alt+F3Command FCommand F or Alt F3Command F to toggle between panes. So doing, the search and replace strings are preserved.
  • To cancel operation and close the pane, press EscapeEscapeEscapeEscapeEscape, Escape or Ctrl+GEscapeEscapeEscapeEscapeEscapeEscape.

Search and replace options

Item Description Search/Replace
find1 Click this button to show the history of the recent entries. Search, replace
closeBlack Click this button to clear the search field. Search, replace
arrowUp  arrowDown Click these buttons to navigate through the occurrences of the search string. Search, replace
exportToTextFile Click this button to show search results in the Find tool window. Search, replace
multiline Click this button to enable entering the search string in several lines. If this button is not pressed, you still can enter search strings that occupy several lines, but should work in the regular expression mode and use escape characters.

For example:

findTextMultiline

Search, replace
Match Case If this check box is selected, WebStorm will distinguish between upper and lowercase letters while searching. Search, replace
Regex If this check box is selected, the search string will be perceived as a regular expression, and the replacement preview is shown in a tooltip ( Refer to the section Example). Search, replace
Words if this check box is selected, WebStorm will search for whole words only, that is, for character strings separated with spaces, tabs, punctuation, or special characters.
This check box is disabled, if the Regular expressions check box is selected.
Search, replace
Preserve Case If this check box is selected, WebStorm retains the case of the first letter and the case of the initial string in general. For example, MyTest will be replaced with Yourtest if you specify yourtest as the replacement.
This check box is disabled, if Regular expressions check box is selected.
Replace
In Selection If this check box is selected, search and replacement will be confined to the selected text only. Replace
Replace Click this button to replace the current occurrence and proceed to the next one. Replace
Replace all Click this button the replace all found occurrences in the current file, or in the selection. Replace
Exclude/Include Click Exclude button to skip the current occurrence and exclude it from the Replace all operation. The button for this occurrence changes to Include. Replace
cogwheel_blue Click this button to reveal the list of additional options:
  • Comments only - select this option to confine search to comments, ignoring the other occurrences.
  • String literals only - select this option to confine search to string literals, ignoring the other occurrences.
Search, replace

Example. Finding and replacing a string using regular expression.

Consider the following XML code fragment:

<new product="ij" category="105" title="Multiline search and replace in the current file" />
<new product="ij" category="105" title="Improved search and replace in the current file" />
<new product="ij" category="105" title="Regexp shows replacement preview" />
          ...
      

Suppose you want to replace an attribute within an element (title) with an expanded tag <title></title>, which contains some arbitrary string in double-quotes within.

This is how it's done.

  1. With the XML file in question opened in the editor, press Ctrl+RCtrl+RCtrl+RCtrl+RShift+Alt+5Ctrl+HCtrl+HCtrl+FCommand RCommand RCommand R. The Replace pane appears on top of the editor.
  2. Since you want to replace all the title attributes, regardless of the actual strings contained therein, use regular expressions. Make sure that the check box Regex is selected. Thus everything you type in the Search and Replace fields will be perceived as the regular expressions.
  3. In the Search field, start typing regular expression that describes all title attributes. Note that though the regular expression \stitle=".*?"\s*[/>]* matches contents of the title attribute, it is recommended to capture the groups for referencing them in the Replace field:
        \stitle="(.*)?"\s*(/>*)
    

    Note that for the regular expressions replacement preview is shown at the tooltip.

    replaceText

  4. Then, in the Replace field, type the following regular expression:
        $2<title>$1</title>
    
  5. Click Replace, or Replace All.

As you see, the second capture group (/>) is moved ahead to close the <new> element, while the first capture group <, which matches any string in double quotes, is moved to the element <title>.

See Also

Reference:

Getting Started:

Web Resources: