PhpStorm 2021.2 Help

Rename refactorings

Rename refactorings allow you to rename symbols and files with all the references to them in the code corrected automatically.

Rename a symbol

  1. Select an item to be renamed.

    • To select a file, click the desired file in the Project tool window.

    • To select a symbol in the editor, place the caret at the name of the symbol to be renamed.

    • To select a symbol in the Project tool window, make sure that the members are shown, and then click the desired symbol.

    • To select a symbol in the Structure view, click the desired symbol in the Structure tool window Alt+7.

  2. Select Refactor | Rename from the main or context menu or press Shift+F6.

    The subsequent behavior depends on the refactoring mode selected under Settings/Preferences | Editor | Code Editing | Specify refactoring options.

    • By default, the In the editor option is selected and the suggested name appears right below the symbol. You can either accept the suggestion, or type a new name you can type a new name in the highlighted line in the editor. If you press Shift+F6 once more, PhpStorm will display the Rename dialog with more options.

    • If the In modal dialogs option is selected, the Rename dialog opens immediately.

  3. PhpStorm displays the Rename in comments and strings icon and the Rename in text occurrences icon next to the highlighted element.

    The in-place rename refactoring

    You can click these icons or press Tab to open the context menu and select the additional rename options.

    The inplace rename refactoring dialog
    • Comments and strings: the occurrences of the symbol will be also renamed in comments and string literals.

    • Text occurrences: the occurrences of the symbol will be also renamed in files that don't contain any source code (documentation, text files, HTML files, and so on).

  4. If you want to change other refactoring options or preview the refactoring results, click the More options link or press Shift+F6. In the dialog that opens, you can select the refactoring scope and click Preview to preview the changes in a separate tool window before applying them.

    The Rename dialog

Rename a file or directory

  1. Select a desired file in the Project tool window.

  2. Choose Refactor | Rename on the main or context menu or press Shift+F6.

  3. In the Rename dialog that opens, specify the new filename.

    • Select the Search in comments and strings checkbox to let PhpStorm apply changes to comments and strings.

  4. Press Preview to observe possible changes in Find Tool Window. Press Refactor to proceed.

    PhpStorm finds all the occurrences of the filename and changes them respectively.

Last modified: 18 May 2021