Extract/Introduce variable
Refactor | Extract/Introduce | Variable
CtrlAlt0V
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.
In the editor, select the expression to be replaced with a variable.
Press CtrlAlt0V or select Refactor | Variable 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:note
CLion saves your choice as default setting for the next attempt of the Extract variable refactoring.
Thanks for your feedback!