# Code Style. Go

> **TL;DR**
> Open settings by pressing `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+Alt+S` (NetBeans), `Ctrl+Alt+S` (Visual Studio), `⌘ Comma` (Visual Studio (macOS)), `Ctrl+Alt+S` (Eclipse), `⌘ Comma` (Eclipse (macOS)) and navigate to `Editor | Code Style`.
>
>
>
> Reformat code: `Ctrl+Alt+L` (Windows), `⌘ ⌥ L` (macOS), `⌘ ⌥ L` (IntelliJ IDEA Classic (macOS)), `⌘ ⌥ L` (macOS System Shortcuts), `Ctrl+Alt+L` (XWin), `Ctrl+Alt+L` (GNOME), `Alt+Shift+L` (KDE), `Ctrl+Alt+L` (Emacs), `Ctrl+Alt+L` (Sublime Text), `⌘ ⌥ L` (Sublime Text (macOS)), `Alt+Shift+F` (NetBeans), `Ctrl+Alt+Enter` (Visual Studio), `⌘ ⌥ ⏎` (Visual Studio (macOS)), `Ctrl+Alt+L` (Eclipse), `⌘ ⇧ F` (Eclipse (macOS))

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

> **TL;DR**
> `File | Settings | Editor | Code Style | SQL | <sql_dialect> | Tabs and Indents` for Windows and Linux
>
>
>
> `IntelliJ IDEA | Settings | Editor | Code Style | SQL | <sql_dialect> | Tabs and Indents` for macOS
>
>
>
> `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+Alt+S` (NetBeans), `Ctrl+Alt+S` (Visual Studio), `⌘ Comma` (Visual Studio (macOS)), `Ctrl+Alt+S` (Eclipse), `⌘ Comma` (Eclipse (macOS)) ![the Settings icon](https://resources.jetbrains.com.cn/help/img/idea/2026.2/app.expui.general.settings.svg)
>
>
>
> As <sql_dialect>, select the SQL dialect on the [Code Style. SQL](settings-code-style-sql.html) page.

Configure code style for indents, TAB and SPACE characters.

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

| Item | Description |
| --- | --- |
|  Use tab character |    Use the `Tab` (Windows), `⇥` (macOS), `⇥` (IntelliJ IDEA Classic (macOS)), `⇥` (macOS System Shortcuts), `Tab` (XWin), `Tab` (GNOME), `Tab` (KDE), `Tab` (Emacs), `Tab` (Sublime Text), `⇥` (Sublime Text (macOS)), `Tab` (NetBeans), `Tab` (Visual Studio), `⇥` (Visual Studio (macOS)), `Tab` (Eclipse), `⇥` (Eclipse (macOS)) key for indentation. When the checkbox is cleared, IntelliJ IDEA uses spaces instead of tabs.  By default, the checkbox is cleared.      |
|  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.  By default, the checkbox is cleared.      |
|  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: `8`.    |
|  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.      By default, the checkbox is cleared.     |

## 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](settings-code-style.html#rightMargin) 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](settings-code-style.html#wrapOnTyping).    * 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 parameters. In Go, a function can have one or more result parameters, which are declared in the function signature after the parameter list, and are used to return values from the function to the caller. The result parameters are specified using the return type(s) of the function.     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](https://resources.jetbrains.com.cn/help/img/idea/2026.2/go_go_use_backquotes_for_imports_set.png) \| ![Use backquotes for imports](https://resources.jetbrains.com.cn/help/img/idea/2026.2/go_use_backquotes_for_imports_cleared.png) \|    |
| Add parentheses for a single import | Add parentheses for the `import` section even when it has only one `import` statement. |
| Remove redundant import aliases | Removes the alias when the alias name matches dependency name. For example, the `logrus` alias will be removed from the following import entry:    ```GO                     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` statements in alphabetical order. Packages from standard libraries are mixed with third party packages. ![gofmt Sorting type](https://resources.jetbrains.com.cn/help/img/idea/2026.2/go_gofmt_sorting_type.png)    * goimports: sorts `import` statements in a specific order, placing standard library packages first, then third-party packages, and then local packages. ![goimports Sorting type](https://resources.jetbrains.com.cn/help/img/idea/2026.2/go_goimports_sorting_type.png)    * none: does not sort `import` statements. ![none Sorting type](https://resources.jetbrains.com.cn/help/img/idea/2026.2/go_none_sorting_type.png)    |
| Move all imports to a single declaration | Groups all `import` statements into a single block at the top of the file.     \| Disabled \| Enabled \| \| --- \| --- \| \| ![Move all imports in a single declaration](https://resources.jetbrains.com.cn/help/img/idea/2026.2/go_move_all_imports_in_a_single_declaration.png) \| ![Move all imports in a single declaration](https://resources.jetbrains.com.cn/help/img/idea/2026.2/go_move_all_imports_in_a_single_declaration_disabled.png) \|    |
| Group packages from Go SDK | Group import statements that belong to Go SDK packages together. For example, import statements from packages like `fmt`, `errors` will be grouped together.     \| Disabled \| Enabled \| \| --- \| --- \| \| ![Group packages from Go SDK enabled](https://resources.jetbrains.com.cn/help/img/idea/2026.2/go_group_packages_from_go_sdk_off.png) \| ![Group packages from Go SDK disabled](https://resources.jetbrains.com.cn/help/img/idea/2026.2/go_group_packages_from_go_sdk_on.png) \|                      Note that this setting does not move import statements together if they are separated by statements from other packages. To group all import statements in a single section, select Move all packages to a single group.     ![Move all                         packages to a single group](https://resources.jetbrains.com.cn/help/img/idea/2026.2/go_move_all_packages_to_a_single_group.png)  |
| Group | Group import statement according to the option that you chose. You can select the following options:       * Current project packages: groups packages that belong to the current project. It means that this setting separates current project packages from any packages from external libraries (Go SDK, libraries from the `go.mod` file, files from the `vendor` directory, and so on).    * Imports starting with: groups packages that start with a certain prefix. You can enumerate all the prefixes separating them with comma. All the corresponding packages will be moved to a single group. ![Imports starting with](https://resources.jetbrains.com.cn/help/img/idea/2026.2/go_imports_starting_with.png)    |

## Other

| Item | Description |
| --- | --- |
| Add a leading space to comments | Add a space between double slashes and a comment text.     \| Disabled \| Enabled \| \| --- \| --- \| \| ![Add a leading space to comments](https://resources.jetbrains.com.cn/help/img/idea/2026.2/go_add_a_leading_space_to_comments_off.png) \| ![Add a leading space to comments](https://resources.jetbrains.com.cn/help/img/idea/2026.2/go_add_a_leading_space_to_comments_on.png) \|     To exclude comments that start with a certain prefixes, click the Add icon (![the Add icon](https://resources.jetbrains.com.cn/help/img/idea/2026.2/app.expui.general.add.svg)), type the prefix, and click OK.     ![exclude comments that start with a certain prefixes](https://resources.jetbrains.com.cn/help/img/idea/2026.2/go_exclude_comments_that_start_with_a_certain_prefixes.png)  |
| Column width for Fill paragraph | Specify the maximum number of characters allowed in a comment before the text is wrapped. The limit is applied to the comment text and redistributes lines, spaces, and line breaks in such a way so that the lines end up fitting within a certain maximum width. The default is 80 characters.     \| Before \| After \| \| --- \| --- \| \| ![Column width for Fill paragraph](https://resources.jetbrains.com.cn/help/img/idea/2026.2/go_column_width_for_fill_paragraph_before.png) \| ![Column width for Fill paragraph](https://resources.jetbrains.com.cn/help/img/idea/2026.2/go_column_width_for_fill_paragraph_after.png) \|    |
| On Reformat Code action | Automatically run gofmt when code is reformatted. By default, to reformat code, press `Ctrl+Alt+L` (Windows), `⌘ ⌥ L` (macOS), `⌘ ⌥ L` (IntelliJ IDEA Classic (macOS)), `⌘ ⌥ L` (macOS System Shortcuts), `Ctrl+Alt+L` (XWin), `Ctrl+Alt+L` (GNOME), `Alt+Shift+L` (KDE), `Ctrl+Alt+L` (Emacs), `Ctrl+Alt+L` (Sublime Text), `⌘ ⌥ L` (Sublime Text (macOS)), `Alt+Shift+F` (NetBeans), `Ctrl+Alt+Enter` (Visual Studio), `⌘ ⌥ ⏎` (Visual Studio (macOS)), `Ctrl+Alt+L` (Eclipse), `⌘ ⇧ F` (Eclipse (macOS)). |

## See also

### Procedures

[Code style schemes](configuring-code-style.html)

