GoLand 2023.2 Help

Extract/Introduce variable

If you come across an expression that is hard to understand or it is duplicated in several places throughout your code, the Extract Variable refactoring Control+Alt+V can help you deal with those problems placing the result of such expression or its part into a separate variable that is less complex and easier to understand. Plus, it reduces the code duplication.

You can use the Introduce Variable refactoring to extract variadic arguments into a new slice variable.

Extract a variable

  1. In the editor, select an expression or its part that you want to extract. You can also position the caret within the expression, in this case GoLand offers you a list of potential code selections.

  2. Press Control+Alt+V or from the main menu, select Refactor | Extract/Introduce | Variable.

  3. Select a name suggested in the popup or type your own and press Enter.

    If GoLand finds more than one occurrence, it lets you specify a scope and extract just a part of the found occurrences and not just all of them. GoLand also displays the Gear icon that you can use to configure more options.

    Example of the Extract a variable refactoring
Last modified: 23 August 2023