Extract/Introduce variable
The Extract Variable refactoring puts the result of the selected expression into a variable. It declares a new variable and uses the expression as an initializer. The original expression is replaced with the new variable.
This refactoring is available for C/C++, Objective-C/C++, Python and JavaScript.
Extract a variable in-place
In the editor, select the expression to be replaced with a variable.
Press Control+Alt+V or select
from the context menu.If more than one occurrence of the selected expression is found, select Replace this occurrence only or Replace all occurrences in the popup.
Specify the name of the variable. You can choose from the list of suggestions or set another name.
If you want to apply automatic type declaration for the variable, set the Declare auto checkbox.
When applicable, you can also declare a variable as
const
by setting Declare const: