llms.txt: machine-readable documentation index. Markdown version of this page is also available.

IntelliJ IDEA 2026.3 Help

Code Style. Go

Use this page to configure formatting options for Go files. When you change these settings, the Preview pane shows how this will affect your code.

Tabs and Indents

Indentation widths are measured in spaces, not in tab characters. For example, an indent of 4 with a tab size of 4 uses one tab when Use tab character is selected.

Item

Description

Use tab character

Use the Tab key for indentation. When the checkbox is cleared, IntelliJ IDEA uses spaces instead of tabs. This checkbox is selected by default.

Smart tabs

  • If this checkbox is selected, the indentation for nested code blocks will use tabs and spaces as needed, while alignment indentation will use only spaces.

  • If this checkbox is cleared, only tabs are used. This means that a group of spaces that fits the specified tab size is automatically replaced with a tab, which may result in breaking fine alignment.

The Smart tabs checkbox is available if the Use tab character option is enabled. This checkbox is cleared by default.

Tab size

In this field, specify the number of spaces included in a tab. Default value: 4.

Indent

In this field, specify the number of spaces to be inserted for each indent level. Default value: 4.

Continuation indent

Specify the indentation for lines that continue from the previous line, making it clear that they are part of the same statement or block of code. Continuation indents are used when a single statement is too long to fit on one line.

Default value: 4.

Keep indents on empty lines

If this checkbox is selected, IntelliJ IDEA will keep indents on the empty lines as if they contained some code.

If this checkbox is cleared, IntelliJ IDEA will delete the tab characters and spaces.

This checkbox is cleared by default.

Wrapping and Braces

Configure wrapping options and the usage of braces.

Item

Description

Hard wrap at

Use the Hard wrap at field to specify a margin space required on the right side of an element. If you select the Default option, then a value of the right margin from the global settings is used.

Wrap on typing

Use the Wrap on typing settings to specify how the edited text is fitted in the specified Hard wrap at:

  • Default: in this case IntelliJ IDEA uses the Wrap on typing option that is specified in the global settings.

  • Yes: in this case IntelliJ IDEA uses the value specified in the Right Margin field.

  • No: in this case this option is switched off and a line can exceed the value specified in the right margin.

Visual guides

Use the Visual guides field to specify multiple right margins. You can leave a default value or enter the number of spaces for your margin. If you want to specify several margins, enter numbers separated by comma.

Function call arguments

Select wrapping options for function call arguments. In Go, function call arguments are the values that are passed to a function when it is called.

You can select between the following options:

  • Do not wrap: when this option is selected, no special wrapping style is applied, the nested alignment and braces settings are ignored.

  • Wrap if long: select this option to have lines going beyond the right margin wrapped with proper indentation.

  • Wrap always: select this option to have all elements in lists wrapped so that there is one element per line with proper indentation.

  • Chop down if long: select this option to have elements in lists that go beyond the right margin wrapped so that there is one element per line with proper indentation.

You can apply the previous options to opening and closing parentheses:

  • New line after '(': add a new line after an opening parenthesis.

  • Place ')' on new line: add a new line before a closing parenthesis.

Composite literals

Select wrapping options for composite literals. In Go, a composite literal is a compact notation for creating a value of a composite type, which includes arrays, slices, maps, and structs.

You can select between the following options:

  • Do not wrap: when this option is selected, no special wrapping style is applied, the nested alignment and braces settings are ignored.

  • Wrap if long: select this option to have lines going beyond the right margin wrapped with proper indentation.

  • Wrap always: select this option to have all elements in lists wrapped so that there is one element per line with proper indentation.

  • Chop down if long: select this option to have elements in lists that go beyond the right margin wrapped so that there is one element per line with proper indentation.

You can apply the previous options to opening and closing parentheses:

  • New line after '(': add a new line after an opening parenthesis.

  • Place ')' on new line: add a new line before a closing parenthesis.

Function parameters

Select wrapping options for function parameters. In Go, function parameters are variables that are declared as part of a function signature and are used to pass data to the function when it is called. The values passed to the function as arguments are assigned to the function's parameters, allowing the function to operate on the data.

You can select between the following options:

  • Do not wrap: when this option is selected, no special wrapping style is applied, the nested alignment and braces settings are ignored.

  • Wrap if long: select this option to have lines going beyond the right margin wrapped with proper indentation.

  • Wrap always: select this option to have all elements in lists wrapped so that there is one element per line with proper indentation.

  • Chop down if long: select this option to have elements in lists that go beyond the right margin wrapped so that there is one element per line with proper indentation.

You can apply the previous options to opening and closing parentheses:

  • New line after '(': add a new line after an opening parenthesis.

  • Place ')' on new line: add a new line before a closing parenthesis.

Function result parameters

Select wrapping options for function result parameters. In Go, result parameters appear after the parameter list in a function signature. They define the values that the function returns.

You can select between the following options:

  • Do not wrap: when this option is selected, no special wrapping style is applied, the nested alignment and braces settings are ignored.

  • Wrap if long: select this option to have lines going beyond the right margin wrapped with proper indentation.

  • Wrap always: select this option to have all elements in lists wrapped so that there is one element per line with proper indentation.

  • Chop down if long: select this option to have elements in lists that go beyond the right margin wrapped so that there is one element per line with proper indentation.

You can apply the previous options to opening and closing parentheses:

  • New line after '(': add a new line after an opening parenthesis.

  • Place ')' on new line: add a new line before a closing parenthesis.

Imports

Configure code style rules for the import section.

Item

Description

Use backquotes for imports

Replace double quotes with backquotes.

Enabled

Disabled

go_use_backquotes_for_imports_cleared
Use backquotes for imports

Add parentheses for a single import

Add parentheses around a single import declaration.

Remove redundant import aliases

Remove an import alias when it matches the package qualifier and no other qualifier is required. For example, the logrus alias is removed from the following import entry:

import ( logrus "github.com/sirupsen/logrus" )

Sorting type

Select what style to use for sorting the import statements. You can select between the following options:

  • gofmt: sorts import paths alphabetically within each existing import group.

    gofmt Sorting type
  • goimports: sorts import paths alphabetically. It puts paths that contain a period into a separate group and puts paths that start with appengine into another group. The options below can add groups for Go SDK and local packages.

    goimports Sorting type
  • none: does not sort import statements.

    none Sorting type

Move all imports to a single declaration

Combine non-C imports into one import declaration and sort them.

Disabled

Enabled

Move all imports in a single declaration
Move all imports in a single declaration

Group packages from Go SDK

Put imports from Go SDK packages in a separate group. For example, imports from fmt and errors are grouped together.

Disabled

Enabled

Group packages from Go SDK enabled
Group packages from Go SDK disabled

The formatter keeps imports in separate groups when blank lines separate them. To put Go SDK imports from all groups together, select Move all packages to a single group.

Move all                         packages to a single group

Group

Select Group to create a separate group for local imports. Then select one of the following options:

  • Current project packages: create a separate group for packages that belong to the current project.

  • Imports starting with: create a separate group for imports whose paths start with one of the comma-separated prefixes.

    Imports starting with

Other

Item

Description

Add a leading space to comments

Add a space after // in line comments.

Disabled

Enabled

Add a leading space to comments
Add a leading space to comments

To exclude comments that start with a specific prefix, click the Add icon (the Add icon), type the prefix, and click OK.

exclude comments that start with a certain prefixes

Column width for Fill paragraph

Set the maximum line width that the Fill Paragraph action uses in Go comments. The action uses a smaller width when indentation and the editor right margin leave less space. The default is 80 characters.

Before

After

Column width for Fill paragraph
Column width for Fill paragraph

On Reformat Code action

Run gofmt after you invoke Reformat Code. This option requires a configured Go SDK that contains gofmt. The option is enabled by default.

22 September 2026