# 重新格式化文件对话框

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

> **TL;DR**
> `代码 | 格式化代码`
>
>
>
> `Ctrl+Alt+Shift+L` (Windows), `⌘ ⌥ ⇧ L` (macOS), `⌘ ⌥ ⇧ L` (IntelliJ IDEA Classic (macOS)), `⌘ ⌥ ⇧ L` (macOS System Shortcuts), `Ctrl+Alt+Shift+L` (XWin), `Ctrl+Alt+Shift+L` (GNOME), `Ctrl+Alt+Shift+L` (KDE), `Ctrl+Alt+Shift+L` (Emacs), `Ctrl+Alt+Shift+L` (Sublime Text), `⌘ ⌥ ⇧ L` (Sublime Text (macOS)), `Ctrl+Alt+Shift+L` (VSCode), `⌘ ⌥ ⇧ L` (VSCode (macOS))

当您在当前文件的编辑器中按下 `Ctrl+Alt+Shift+L` (Windows), `⌘ ⌥ ⇧ L` (macOS), `⌘ ⌥ ⇧ L` (IntelliJ IDEA Classic (macOS)), `⌘ ⌥ ⇧ L` (macOS System Shortcuts), `Ctrl+Alt+Shift+L` (XWin), `Ctrl+Alt+Shift+L` (GNOME), `Ctrl+Alt+Shift+L` (KDE), `Ctrl+Alt+Shift+L` (Emacs), `Ctrl+Alt+Shift+L` (Sublime Text), `⌘ ⌥ ⇧ L` (Sublime Text (macOS)), `Ctrl+Alt+Shift+L` (VSCode), `⌘ ⌥ ⇧ L` (VSCode (macOS))时，将显示此对话框。 如果您从主菜单中选择  `代码 | 格式化代码` 或按下 `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` (VSCode), `⌥ ⇧ F` (VSCode (macOS))，GoLand 会尝试自动重新格式化指定范围的源代码。

|  项目  |  描述  |
| --- | --- |
|  仅未提交到 VCS 的更改  |     如果选中此复选框，则重新格式化将仅应用于本地已更改但尚未提交到存储库的代码。       此选项仅适用于版本控制下的文件。     |
|  选中的文本  |  选择此选项以重新格式化当前选定的源代码片段。  |
|  整文件  |  选择此选项以重新格式化当前文件中的所有源代码。  |
|  选项  |
|  优化导入  |  选中此复选框以从选定范围内的代码中移除未使用的导入语句。  |
|  重新排列代码  |     选中此复选框以根据   排列选项卡  中指定的配置重新排序您的源代码条目，这些配置位于您的 [代码样式设置](settings-code-style.html)中。       此复选框对 Python 文件不可用。     |
|  代码清理  |     选择此选项以运行代码清理检查。 GoLand 会查找并自动修复潜在的有问题的代码片段。     |
|  不保留换行符  |  根据代码样式设置重新格式化换行符。 此选项将覆盖  `重新格式化时保留 \| 换行符号` 设置。  |
|  运行  |  单击此按钮以开始重新格式化指定范围内的源代码。  |

> **Tip:**
> 您可以定义规则并在编写代码时对其进行格式化。 要为 前往 定义格式化规则，请打开   设置  对话框（ `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))），然后导航到 Editor | Code Style | 前往。

## See also

### 操作流程

[重新格式化并重新排列代码](reformat-and-rearrange-code.html)

### 参考

[代码样式](settings-code-style.html)

