# Extract constant

> For the complete documentation index, see [llms.txt](https://www.jetbrains.com/help/go/2026.3/llms.txt).

The Extract Constant refactoring makes your source code easier to read and maintain. It also helps you avoid usage of hardcoded constants without any explanation about their values or purpose.

Procedure:

1. In the editor, select an expression or declaration of a variable you want to replace with a constant.

2. Press `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)), `Ctrl+Alt+C` (VSCode), `Ctrl+Alt+C` (VSCode (macOS)) to introduce a constant or select `Refactor | Extract | Constant` in the main menu.

> **Note:**
> By default, GoLand uses the in-place refactoring. To use the  dialog for the refactoring,           open 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+Comma` (VSCode), `⌘ Comma` (VSCode (macOS))), go to Editor | Code Editing, and select the In modal dialogs refactoring option in the Refactorings area.

3. Select an expression you want to extract as constant and press `Enter` (Windows), `⏎` (macOS), `⏎` (IntelliJ IDEA Classic (macOS)), `⏎` (macOS System Shortcuts), `Enter` (XWin), `Enter` (GNOME), `Enter` (KDE), `Enter` (Emacs), `Enter` (Sublime Text), `⏎` (Sublime Text (macOS)), `Enter` (VSCode), `⏎` (VSCode (macOS)). Select the number of occurrences you want to replace and a name you want to use.

[Video](https://resources.jetbrains.com/help/img/idea/2026.3/go_extract_constant.mp4)

[Code snippet at GitHub](https://github.com/apronichev/documentation-code-examples/blob/master/extractConstantVariable/main.go)

## See also

### External Links

