PyCharm 2024.2 Help

Rename refactorings

Use the Rename refactoring to change names of symbols, files, variables, functions, packages, modules and all the references to them throughout code.

Renaming local variables or functions can be done easily inline since only the limited scope is affected. Renaming classes or their methods could potentially impact a lot of files. Preview potential changes before you refactor.

Rename a code element inline

  1. Place the caret at the element that you want to rename and press Shift+F6.

    If there are occurrences of this element in comments, strings, or text files, inline icons are displayed:

    Inline icons of renaming options
  2. Click the icons and select the desired options:

    Options for inline rename refactoring

    To open the Rename dialog, click More options or press Shift+F6 again.

  3. Type the new name of the element. All occurrences will change automatically:

  4. Press Tab or Enter to apply the refactoring. If there are changes that require your attention, PyCharm opens the Find tool window where you can check the results and confirm the refactoring by clicking Do Refactor.

Use a quick-fix or a gutter icon

  1. In the editor start renaming a code element. PyCharm will display the Rename the usages of icon in the gutter.

  2. Click the gutter icon or press Alt+Enter and apply a suggestion.

    Rename inline

    PyCharm renames the code element and updates its usages accordingly.

    Rename refactoring result

Rename a directory or a module

  1. In the Project tool window right-click a directory or a module that you want to rename.

  2. From the context menu, select Refactor | Rename (Shift+F6).

  3. In the Rename dialog that opens, type the new name, specify additional options and the scope of the refactoring, and click Refactor.

Use the Rename dialog

  1. In the editor, select the element you want to rename. If you need to rename a file, select one in the Project tool window.

  2. Press Shift+F6 or go to Refactor | Rename in the main menu.

  3. You can perform the rename refactoring inline or press Shift+F6 again to open the Rename dialog. Enter a new name of the element to enable the Preview and Refactor buttons.

    The Rename dialog

    You can specify additional options. For example, specify where to search for element occurrences, or what else to rename. You can also specify a scope for the refactoring.

  4. Click Preview to see the potential changes or click Refactor.

    When you click Preview, PyCharm opens the Find tool window with the results of found usages where you can check the results and confirm the refactoring (Do Refactor).

Next time you invoke the Rename refactoring, PyCharm remembers the options you have specified inside the Rename dialog.

Last modified: 28 June 2024