# Code refactoring

[Refactoring](https://en.wikipedia.org/wiki/Code_refactoring) is a process of improving your source code without creating a new functionality. Refactoring helps you keep your code solid , [dry](https://en.wikipedia.org/wiki/Don%27t_repeat_yourself),  and easy to maintain.

## Invoke refactoring

Procedure:

1. Select an item to refactor. You can select a file/folder in the Project tool window or expression/symbol in the editor.

2. Press `Ctrl+Alt+Shift+T` (Windows), `⌃ T` (macOS), `⌘ ⌥ ⇧ T` (IntelliJ IDEA Classic (macOS)), `⌃ S` (macOS System Shortcuts), `Ctrl+Alt+Shift+T` (XWin), `Ctrl+Alt+Shift+T` (GNOME), `Ctrl+Alt+Shift+T` (KDE), `Ctrl+Alt+Shift+T` (Emacs), `Ctrl+Alt+Shift+T` (Sublime Text), `⌃ T` (Sublime Text (macOS)), `Ctrl+Alt+Shift+T` (NetBeans), `Ctrl+Shift+R` (Visual Studio), `⌘ ⇧ R` (Visual Studio (macOS)), `Ctrl+Alt+Shift+T` (Eclipse), `⌃ T` (Eclipse (macOS)) to open a list of refactorings that can be selected.

![refactor this popup](https://resources.jetbrains.com.cn/help/img/idea/2026.2/refactoring_invoke.png)

Alternatively, you can use a keyboard shortcut for a specific refactoring.

You can also make a [multi-caret selection](multicursor.html#add-carets-at-selected-locations) for an extended range of refactoring operations, including Encapsulate Fields, Move Static Members, Extract Delegate, Extract Interface, and Extract Superclass. To utilize this feature, place the caret in each member you want to apply the refactoring to, and the IDE will automatically preselect and check these members in the refactoring dialog.

If you need to undo your refactoring, press `Ctrl+Z` (Windows), `⌘ Z` (macOS), `⌘ Z` (IntelliJ IDEA Classic (macOS)), `⌘ Z` (macOS System Shortcuts), `Ctrl+Z` (XWin), `Ctrl+Z` (GNOME), `Ctrl+Z` (KDE), `Ctrl+Shift+Minus` (Emacs), `Ctrl+Z` (Sublime Text), `⌘ Z` (Sublime Text (macOS)), `Ctrl+Z` (NetBeans), `Ctrl+Z` (Visual Studio), `⌘ Z` (Visual Studio (macOS)), `Ctrl+Z` (Eclipse), `⌘ Z` (Eclipse (macOS)).

Procedure: Invoke refactoring from the Structure tool window

1. In the left tool bar, click ![the Structure tool window](https://resources.jetbrains.com.cn/help/img/idea/2026.2/app.expui.toolwindow.structure.svg) to open the Structure tool window.

2. In the Structure tool window, select methods or fields for which you want to invoke the refactoring actions, right-click them and from the context menu select the name of the refactoring you want to apply.

![Invoke refactoring from the Structure tool window](https://resources.jetbrains.com.cn/help/img/idea/2026.2/refactoring_from_structure.png)

> **Note:**
> You can perform the same procedure from the Project view as well.

## Preview refactoring changes

Procedure:

For some refactorings, IntelliJ IDEA lets you preview the changes before applying them.

1. Click Preview in the Refactoring Preview dialog to see potential changes (the list of usages where the refactoring will be performed).

![Refactoring dialog](https://resources.jetbrains.com.cn/help/img/idea/2026.2/specific_refactor_dialog.png)

2. In the  [Find](find-tool-window.html) tool window that opens, check the changes that are going to be made. You can exclude `Delete` (Windows), `⌦` (macOS), `⌦` (IntelliJ IDEA Classic (macOS)), `⌦` (macOS System Shortcuts), `Delete` (XWin), `Delete` (GNOME), `Delete` (KDE), `Delete` (Emacs), `Delete` (Sublime Text), `⌦` (Sublime Text (macOS)), `Delete` (NetBeans), `Delete` (Visual Studio), `⌦` (Visual Studio (macOS)), `Delete` (Eclipse), `⌦` (Eclipse (macOS)) or remove `Ctrl+X` (Windows), `⌘ X` (macOS), `⌘ X` (IntelliJ IDEA Classic (macOS)), `⌘ X` (macOS System Shortcuts), `Ctrl+X` (XWin), `Ctrl+X` (GNOME), `Ctrl+X` (KDE), `Shift+Delete` (Emacs), `Ctrl+X` (Sublime Text), `⌘ X` (Sublime Text (macOS)), `Ctrl+X` (NetBeans), `Ctrl+X` (Visual Studio), `⌘ X` (Visual Studio (macOS)), `Ctrl+X` (Eclipse), `⌘ X` (Eclipse (macOS)) changes that you consider unnecessary.

![Refactoring Preview window](https://resources.jetbrains.com.cn/help/img/idea/2026.2/refactoring_preview.png)

3. Click Do Refactor to proceed with the changes.

## Resolve conflicts

Procedure:

When IntelliJ IDEA encounters problems with your refactoring, it opens a dialog with the list of conflicts and their brief descriptions.

![refactoring_confilicts_dialog.png](https://resources.jetbrains.com.cn/help/img/idea/2026.2/refactoring_conflicts_dialog.png)

* Click Refactor Anyway to ignore the problem and proceed.

* Click Open in Find Window to open the conflict entries in the Find tool window and deal with them further.

* In the Find tool window, you can apply the refactor by selecting Refactor or click Cancel and return to the editor.

## Configure refactoring settings

Procedure:

1. In the Settings dialog (`Ctrl+Alt+S` (Windows), `⌘ Comma` (macOS), `⌘ Comma` (IntelliJ IDEA Classic (macOS)), `⌘ Comma` (macOS System Shortcuts), `Ctrl+Alt+S` (XWin), `Ctrl+Alt+S` (GNOME), `Ctrl+Alt+S` (KDE), `Ctrl+Alt+S` (Emacs), `Ctrl+Alt+S` (Sublime Text), `⌘ Comma` (Sublime Text (macOS)), `Ctrl+Alt+S` (NetBeans), `Ctrl+Alt+S` (Visual Studio), `⌘ Comma` (Visual Studio (macOS)), `Ctrl+Alt+S` (Eclipse), `⌘ Comma` (Eclipse (macOS))), select `Editor | Code Editing`.

2. On the Code Editing page, in the Refactorings section, adjust the refactoring options and click OK.

> **Tip:**
> You can also adjust the refactoring intentions, in `Editor | Intentions`.

## The most popular refactorings supported in IntelliJ IDEA

|  Safe Delete  |  `Alt+Delete` (Windows), `⌘ ⌦` (macOS), `⌘ ⌦` (IntelliJ IDEA Classic (macOS)), `⌘ ⌦` (macOS System Shortcuts), `Alt+Delete` (XWin), `Alt+Delete` (GNOME), `Alt+Delete` (KDE), `Alt+Delete` (Emacs), `Alt+Delete` (Sublime Text), `⌘ ⌦` (Sublime Text (macOS)), `Alt+Delete` (NetBeans), `Ctrl+R, D` (Visual Studio), `⌘ R, D` (Visual Studio (macOS)), `Alt+Delete` (Eclipse), `Alt+Delete` (Eclipse (macOS))  | Makes sure that you do not delete files that are referenced in your source code.  |  [Safe delete](safe-delete.html)  |
| Copy/Move | `F5` (Windows), `F5` (macOS), `F5` (IntelliJ IDEA Classic (macOS)), `⌘ ⌥ Y` (macOS System Shortcuts), `F5` (XWin), `F5` (GNOME), `F5` (KDE), `F5` (Emacs), `F5` (Sublime Text), `F5` (Sublime Text (macOS)), `F5` (NetBeans), `F5` (Visual Studio), `F5` (Visual Studio (macOS)), `F5` (Eclipse), `F5` (Eclipse (macOS))/ `F6` (Windows), `F6` (macOS), `F6` (IntelliJ IDEA Classic (macOS)), `⌘ ⌥ I` (macOS System Shortcuts), `F6` (XWin), `F6` (GNOME), `F6` (KDE), `F6` (Emacs), `F6` (Sublime Text), `F6` (Sublime Text (macOS)), `Ctrl+M` (NetBeans), `Ctrl+R, O` (Visual Studio), `⌘ R, O` (Visual Studio (macOS)), `Alt+Shift+V` (Eclipse), `⌘ ⌥ V` (Eclipse (macOS))  | Copies/Moves an element. |  [Move and copy refactorings](move-refactorings.html)  |
| Extract Method |  `Ctrl+Alt+M` (Windows), `⌘ ⌥ M` (macOS), `⌘ ⌥ M` (IntelliJ IDEA Classic (macOS)), `⌘ ⌥ M` (macOS System Shortcuts), `Ctrl+Alt+M` (XWin), `Ctrl+Alt+M` (GNOME), `Ctrl+Alt+M` (KDE), `Ctrl+Alt+M` (Emacs), `Ctrl+Alt+M` (Sublime Text), `⌘ ⌥ M` (Sublime Text (macOS)), `Alt+Shift+M` (NetBeans), `Ctrl+R, M` (Visual Studio), `⌘ R, M` (Visual Studio (macOS)), `Alt+Shift+M` (Eclipse), `⌘ ⌥ M` (Eclipse (macOS))  | These refactoring actions help you reduce the code duplication.  |  [Extract method](extract-method.html)  |
| Extract Constant |  `Ctrl+Alt+C` (Windows), `⌘ ⌥ C` (macOS), `⌘ ⌥ C` (IntelliJ IDEA Classic (macOS)), `⌘ ⌥ C` (macOS System Shortcuts), `Ctrl+Alt+C` (XWin), `Ctrl+Alt+C` (GNOME), `Ctrl+Alt+C` (KDE), `Ctrl+Alt+C` (Emacs), `Ctrl+Alt+C` (Sublime Text), `⌘ ⌥ C` (Sublime Text (macOS)), `Alt+Shift+C` (NetBeans), `Ctrl+Alt+C` (Visual Studio), `⌘ ⌥ C` (Visual Studio (macOS)), `Ctrl+Alt+C` (Eclipse), `Ctrl+Alt+C` (Eclipse (macOS))  |    |  [Extract constant](extract-constant.html)  |
| Extract Field |  `Ctrl+Alt+F` (Windows), `⌘ ⌥ F` (macOS), `⌘ ⌥ F` (IntelliJ IDEA Classic (macOS)), `⌘ ⌥ F` (macOS System Shortcuts), `Ctrl+Alt+F` (XWin), `Ctrl+Alt+F` (GNOME), `Ctrl+Alt+F` (KDE), `Ctrl+Alt+F` (Emacs), `Ctrl+Alt+F` (Sublime Text), `Ctrl+Alt+F` (Sublime Text (macOS)), `Alt+Shift+E` (NetBeans), `Ctrl+R, F` (Visual Studio), `⌘ R, F` (Visual Studio (macOS)), `Ctrl+Alt+F` (Eclipse), `⌘ ⌥ F` (Eclipse (macOS))  |     |  [Extract field](extract-field.html)  |
| Extract Parameter |  `Ctrl+Alt+P` (Windows), `⌘ ⌥ P` (macOS), `⌘ ⌥ P` (IntelliJ IDEA Classic (macOS)), `⌘ ⌥ P` (macOS System Shortcuts), `Ctrl+Alt+P` (XWin), `Ctrl+Alt+P` (GNOME), `Ctrl+Alt+P` (KDE), `Ctrl+Alt+P` (Emacs), `Ctrl+Alt+P` (Sublime Text), `⌘ ⌥ P` (Sublime Text (macOS)), `Ctrl+Alt+P` (NetBeans), `Ctrl+R, P` (Visual Studio), `⌘ R, P` (Visual Studio (macOS)), `Ctrl+Alt+P` (Eclipse), `⌘ ⌥ P` (Eclipse (macOS))  |    |  [Extract parameter](extract-parameter.html)   |
|  Introduce Variable  |  `Ctrl+Alt+V` (Windows), `⌘ ⌥ V` (macOS), `⌘ ⌥ V` (IntelliJ IDEA Classic (macOS)), `⌘ ⌥ V` (macOS System Shortcuts), `Ctrl+Alt+V` (XWin), `Ctrl+Alt+V` (GNOME), `Alt+Shift+V` (KDE), `Ctrl+Alt+V` (Emacs), `Ctrl+Alt+V` (Sublime Text), `Ctrl+Alt+V` (Sublime Text (macOS)), `Alt+Shift+V` (NetBeans), `Ctrl+R, V` (Visual Studio), `⌘ R, V` (Visual Studio (macOS)), `Alt+Shift+L` (Eclipse), `⌘ ⌥ L` (Eclipse (macOS))  |    |  [Extract/Introduce variable](extract-variable.html)  |
| Rename |  `Shift+F6` (Windows), `⇧ F6` (macOS), `⇧ F6` (IntelliJ IDEA Classic (macOS)), `⌘ ⌥ R` (macOS System Shortcuts), `Shift+F6` (XWin), `Shift+F6` (GNOME), `Shift+F6` (KDE), `Shift+F6` (Emacs), `Shift+F6` (Sublime Text), `⇧ F6` (Sublime Text (macOS)), `Ctrl+R` (NetBeans), `Ctrl+R, R` (Visual Studio), `⌘ R, R` (Visual Studio (macOS)), `Alt+Shift+R` (Eclipse), `⇧ F6` (Eclipse (macOS))  | Renames an element. |  [Rename refactorings](rename-refactorings.html)  |
| Inline |  `Ctrl+Alt+N` (Windows), `⌘ ⌥ N` (macOS), `⌘ ⌥ N` (IntelliJ IDEA Classic (macOS)), `⌘ ⌥ N` (macOS System Shortcuts), `Ctrl+Alt+N` (XWin), `Ctrl+Alt+N` (GNOME), `Ctrl+Alt+N` (KDE), `Ctrl+Alt+N` (Emacs), `Ctrl+Alt+N` (Sublime Text), `⌘ ⌥ N` (Sublime Text (macOS)), `Ctrl+Alt+N` (NetBeans), `Ctrl+R, I` (Visual Studio), `⌘ R, I` (Visual Studio (macOS)), `Alt+Shift+I` (Eclipse), `⌘ ⌥ I` (Eclipse (macOS))  | Inlines an element. Acts as the opposite of extracting. |  [Inline](inline.html)  |
| Change signature |  `Ctrl+F6` (Windows), `⌘ F6` (macOS), `⌘ F6` (IntelliJ IDEA Classic (macOS)), `⌘ ⌥ S` (macOS System Shortcuts), `Ctrl+F6` (XWin), `Ctrl+F6` (GNOME), `Ctrl+6` (KDE), `Ctrl+F6` (Emacs), `Ctrl+F6` (Sublime Text), `Ctrl+F6` (Sublime Text (macOS)), `Ctrl+F6` (NetBeans), `Ctrl+R, S` (Visual Studio), `⌘ R, S` (Visual Studio (macOS)), `Alt+Shift+C` (Eclipse), `⌘ ⌥ C` (Eclipse (macOS))  | Changes the call signature of a method or class.  |  [Change signature](change-signature.html)  |

