# Extract/Introduce variable

> **TL;DR**
> `Refactor | Extract/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)), `⌘ ⌃ ⌥ V` (Xcode), `Ctrl+R, V` (Visual Studio), `⌘ R, V` (Visual Studio (macOS)), `Ctrl+Alt+V` (ReSharper), `⌘ ⌥ V` (ReSharper (macOS)), `Ctrl+Alt+V` (QtCreator), `⌘ ⌥ V` (QtCreator (macOS)), `Alt+Shift+V` (NetBeans), `Alt+Shift+L` (Eclipse), `⌘ ⌥ L` (Eclipse (macOS))

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++,  Python, and [JavaScript](specific-javascript-refactorings.html#javascript_extract_variable).

Procedure: Extract a variable in-place

1. In the editor, select the expression to be replaced with a variable.

2. Press `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)), `⌘ ⌃ ⌥ V` (Xcode), `Ctrl+R, V` (Visual Studio), `⌘ R, V` (Visual Studio (macOS)), `Ctrl+Alt+V` (ReSharper), `⌘ ⌥ V` (ReSharper (macOS)), `Ctrl+Alt+V` (QtCreator), `⌘ ⌥ V` (QtCreator (macOS)), `Alt+Shift+V` (NetBeans), `Alt+Shift+L` (Eclipse), `⌘ ⌥ L` (Eclipse (macOS)) or select `Refactor | Variable` from the context menu.

3. If more than one occurrence of the selected expression is found, select Replace this occurrence only or Replace all occurrences in the popup.

![Extract variable - multiple occurrences](https://resources.jetbrains.com/help/img/idea/2026.2/cl_extractvar_multiple.png)

4. Specify the name of the variable. You can choose from the list of suggestions or set another name.

![Extracting a variable](https://resources.jetbrains.com/help/img/idea/2026.2/cl_extractvar_name.png)

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:

![Extracting a variable - declare options](https://resources.jetbrains.com/help/img/idea/2026.2/cl_extractVariable.png)

> **Note:**
> CLion saves your choice as default setting for the next attempt of the Extract variable refactoring.

