Extract Function#
The extract function refactoring takes a selection of code, moves it into a separate function or method (or constant), and asks for a new function (or constant) name.
- Select a portion of code.
- Open Code Actions using a light bulb icon, or keyboard shortcut (by default
Ctrl + .
(Windows) orCmd + .
). - Select Extract function.
- Enter a new function name and confirm with
Enter
.
Extract Constant#
If you select a constant value, instead of Extract function
, there will be Extract constant
.