# Groovy

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

IntelliJ IDEA 支持 Groovy 和 Groovy 4 语法的 [最新稳定版本](http://groovy-lang.org/download.html)。

Procedure: 启用 Groovy 插件

此功能性依赖于 [Groovy](https://plugins.jetbrains.com/plugin/20393-groovy) 插件，该插件默认在 IntelliJ IDEA 中捆绑并启用。 如果相关功能不可用，请确保您没有禁用插件。

1. 按 `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` (Visual Studio), `⌘ Comma` (Visual Studio (macOS)), `Ctrl+Alt+S` (NetBeans), `Ctrl+Alt+S` (Eclipse), `⌘ Comma` (Eclipse (macOS)) 打开设置，然后选择  `插件` 。

2. 找到  Groovy  插件并点击   启用  。

## 用户接口

Groovy 的用户界面看起来与普通用户界面相似。 不过，它包括 [Groovy 控制台](launching-groovy-interaction-console.html)，您可以从主菜单（  `工具 | Groovy Console` ）打开它。

![Groovy 用户界面](https://resources.jetbrains.com.cn/help/img/idea/2026.3/editor_groovy.png)

最有趣的用户界面部分是 IntelliJ IDEA [编辑器](using-code-editor.html)，因为它允许您在不离开它的情况下调用几乎任何 IDE 功能，这有助于您组织一个拥有更多屏幕空间的布局，因为像工具栏和窗口这样的辅助控件被隐藏了。

通过快捷键访问工具窗口会将输入焦点移到该窗口，因此可以在其上下文中使用所有键盘命令。 需要返回编辑器时，请按 `Escape` (Windows), `⎋` (macOS), `⎋` (IntelliJ IDEA Classic (macOS)), `⎋` (macOS System Shortcuts), `Escape` (XWin), `Escape` (GNOME), `Escape` (KDE), `Escape, Escape` (Emacs), `Escape` (Sublime Text), `⎋` (Sublime Text (macOS)), `Escape` (Visual Studio), `⎋` (Visual Studio (macOS)), `Escape` (NetBeans), `Escape` (Eclipse), `⎋` (Eclipse (macOS))。

以下是调用最常用工具窗口的快捷键列表：

|  工具窗口  |  快捷键  |
| --- | --- |
|  项目  |  `Alt+1` (Windows), `⌘ 1` (macOS), `⌘ 1` (IntelliJ IDEA Classic (macOS)), `⌘ 1` (macOS System Shortcuts), `Alt+1` (XWin), `Alt+1` (GNOME), `Alt+1` (KDE), `Alt+1` (Emacs), `Alt+1` (Sublime Text), `⌘ 1` (Sublime Text (macOS)), `Ctrl+Alt+L` (Visual Studio), `⌘ ⌥ L` (Visual Studio (macOS)), `Ctrl+1` (NetBeans), `Alt+1` (Eclipse), `Alt+1` (Eclipse (macOS))  |
|  版本控制  |  `Alt+9` (Windows), `⌘ 9` (macOS), `⌘ 9` (IntelliJ IDEA Classic (macOS)), `⌘ 9` (macOS System Shortcuts), `Alt+9` (XWin), `Alt+9` (GNOME), `Alt+9` (KDE), `Alt+9` (Emacs), `Alt+9` (Sublime Text), `⌘ 9` (Sublime Text (macOS)), `Alt+9` (Visual Studio), `⌘ 9` (Visual Studio (macOS)), `Alt+9` (NetBeans), `Alt+9` (Eclipse), `⌘ 9` (Eclipse (macOS))  |
|  运行  |  `Alt+4` (Windows), `⌘ 4` (macOS), `⌘ 4` (IntelliJ IDEA Classic (macOS)), `⌘ 4` (macOS System Shortcuts), `Alt+4` (XWin), `Alt+4` (GNOME), `Alt+4` (KDE), `Alt+4` (Emacs), `Alt+4` (Sublime Text), `⌘ 4` (Sublime Text (macOS)), `Alt+4` (Visual Studio), `⌘ 4` (Visual Studio (macOS)), `Alt+4` (NetBeans), `Alt+4` (Eclipse), `⌘ 4` (Eclipse (macOS))  |
|  调试  |  `Alt+5` (Windows), `⌘ 5` (macOS), `⌘ 5` (IntelliJ IDEA Classic (macOS)), `⌘ 5` (macOS System Shortcuts), `Alt+5` (XWin), `Alt+5` (GNOME), `Alt+5` (KDE), `Alt+5` (Emacs), `Alt+5` (Sublime Text), `⌘ 5` (Sublime Text (macOS)), `Alt+5` (Visual Studio), `⌘ 5` (Visual Studio (macOS)), `Alt+5` (NetBeans), `Alt+5` (Eclipse), `⌘ 5` (Eclipse (macOS))  |
|  终端  |  `Alt+F12` (Windows), `⌥ F12` (macOS), `⌥ F12` (IntelliJ IDEA Classic (macOS)), `⌘ ⌃ T` (macOS System Shortcuts), `Alt+F12` (XWin), `Alt+F12` (GNOME), `Alt+F12` (KDE), `Alt+F12` (Emacs), `Alt+F12` (Sublime Text), `⌥ F12` (Sublime Text (macOS)), `Ctrl+Alt+1` (Visual Studio), `⌘ ⌃ 1` (Visual Studio (macOS)), `Alt+F12` (NetBeans), `Alt+F12` (Eclipse), `⌥ F12` (Eclipse (macOS))  |
|  编辑器  |  `Escape` (Windows), `⎋` (macOS), `⎋` (IntelliJ IDEA Classic (macOS)), `⎋` (macOS System Shortcuts), `Escape` (XWin), `Escape` (GNOME), `Escape` (KDE), `Escape, Escape` (Emacs), `Escape` (Sublime Text), `⎋` (Sublime Text (macOS)), `Escape` (Visual Studio), `⎋` (Visual Studio (macOS)), `Escape` (NetBeans), `Escape` (Eclipse), `⎋` (Eclipse (macOS))  |

想专注于代码时，请尝试 [免打扰模式](ide-viewing-modes.html#distraction-free)。 会移除所有工具栏、工具窗口和编辑器选项卡。 要切换到此模式，请转到   视图 | 外观 | 进入免打扰模式  的主菜单。

一种替代免打扰模式的方法是按下 `Ctrl+Shift+F12` (Windows), `⌘ ⇧ F12` (macOS), `⌘ ⇧ F12` (IntelliJ IDEA Classic (macOS)), `⌘ ⇧ F12` (macOS System Shortcuts), `Ctrl+Shift+F12` (XWin), `Ctrl+Shift+F12` (GNOME), `Ctrl+Shift+F12` (KDE), `Ctrl+Shift+F12` (Emacs), `Ctrl+Shift+F12` (Sublime Text), `⌘ ⇧ F12` (Sublime Text (macOS)), `Ctrl+Shift+F12` (Visual Studio), `⌘ ⇧ F12` (Visual Studio (macOS)), `Ctrl+Shift+F12` (NetBeans), `Ctrl+Shift+F12` (Eclipse), `⌘ ⇧ F12` (Eclipse (macOS)) 隐藏所有工具窗口。 您可以再次按下此快捷键将布局恢复到默认设置。

导航栏是 [项目工具窗口](project-tool-window.html)的紧凑替代品。 要访问导航栏，请按 `Alt+Home` (Windows), `⌘ ↑` (macOS), `⌥ Home` (IntelliJ IDEA Classic (macOS)), `⌘ ⌃ ↑` (macOS System Shortcuts), `Alt+Home` (XWin), `Alt+Home` (GNOME), `Alt+Home` (KDE), `Alt+Home` (Emacs), `Alt+Home` (Sublime Text), `⌥ Home` (Sublime Text (macOS)), `Ctrl+F2` (Visual Studio), `⌘ F2` (Visual Studio (macOS)), `Alt+Home` (NetBeans), `Alt+Home` (Eclipse), `⌘ ⌥ B` (Eclipse (macOS))。

![导航栏](https://resources.jetbrains.com.cn/help/img/idea/2026.3/groovy_navigation_bar.png)

IntelliJ IDEA 中的大多数组件（包括工具窗口和弹出窗口）都提供 [快速搜索](speed-search-in-the-tool-windows.html)。 此功能允许您通过搜索查询筛选列表或导航到特定项。

![快速搜索](https://resources.jetbrains.com.cn/help/img/idea/2026.3/groovy_search_for_window.png)

> **Tip:**
> 当您不知道某个操作的快捷方式时，请尝试使用  Find action  功能，按下 `Ctrl+Shift+A` (Windows), `⌘ ⇧ A` (macOS), `⌘ ⇧ A` (IntelliJ IDEA Classic (macOS)), `⌘ ⇧ P` (macOS System Shortcuts), `Ctrl+Shift+A` (XWin), `Ctrl+Shift+A` (GNOME), `Ctrl+Shift+A` (KDE), `Escape, X` (Emacs), `Ctrl+Shift+P` (Sublime Text), `⌘ ⇧ P` (Sublime Text (macOS)), `Ctrl+Shift+A` (Visual Studio), `⌘ ⇧ A` (Visual Studio (macOS)), `Ctrl+I` (NetBeans), `Ctrl+Shift+A` (Eclipse), `⌘ 3` (Eclipse (macOS))。 开始键入即可按名称查找操作、查看其快捷键或调用它。

有关更多信息，请参阅 [用户接口](guided-tour-around-the-user-interface.html)、 [编辑器基础](using-code-editor.html) 和 [工具窗口](tool-windows.html)。

## 编辑器基础

在编辑器中进行工作与其他语言一样，适用于 Groovy，且提供所有由 IntelliJ IDEA 提供的快捷方式。

检查以下最有用的编辑器快捷键：

|  操作  |  描述  |
| --- | --- |
|  移动当前代码行  |  `Ctrl+Shift+Up` (Windows), `⌘ ⇧ ↑` (macOS), `⌘ ⇧ ↑` (IntelliJ IDEA Classic (macOS)), `⌃ ⇧ ↑` (macOS System Shortcuts), `Ctrl+Shift+Up` (XWin), `Ctrl+Shift+Up` (GNOME), `Ctrl+Shift+Up` (KDE), `Ctrl+Shift+Up` (Emacs), `Ctrl+Shift+Up` (Sublime Text), `⌘ ⇧ ↑` (Sublime Text (macOS)), `Ctrl+Alt+Shift+Up` (Visual Studio), `⌃ ⌥ ⇧ ↑` (Visual Studio (macOS)), `Alt+Shift+Page Up` (NetBeans), `Alt+Up` (Eclipse), `⌥ ↑` (Eclipse (macOS)) `Ctrl+Shift+Down` (Windows), `⌘ ⇧ ↓` (macOS), `⌘ ⇧ ↓` (IntelliJ IDEA Classic (macOS)), `⌃ ⇧ ↓` (macOS System Shortcuts), `Ctrl+Shift+Down` (XWin), `Ctrl+Shift+Down` (GNOME), `Ctrl+Shift+Down` (KDE), `Ctrl+Shift+Down` (Emacs), `Ctrl+Shift+Down` (Sublime Text), `⌘ ⇧ ↓` (Sublime Text (macOS)), `Ctrl+Alt+Shift+Down` (Visual Studio), `⌃ ⌥ ⇧ ↓` (Visual Studio (macOS)), `Alt+Shift+Page Down` (NetBeans), `Alt+Down` (Eclipse), `⌥ ↓` (Eclipse (macOS))  |
|  复制一行代码  |  `Ctrl+D` (Windows), `⌘ D` (macOS), `⌘ D` (IntelliJ IDEA Classic (macOS)), `⌘ D` (macOS System Shortcuts), `Ctrl+D` (XWin), `Ctrl+D` (GNOME), `Ctrl+D` (KDE), `Meta+D` (Emacs), `Ctrl+Shift+D` (Sublime Text), `⌘ ⇧ D` (Sublime Text (macOS)), `Ctrl+D` (Visual Studio), `⌘ D` (Visual Studio (macOS)), `Ctrl+D` (NetBeans), `Ctrl+D` (Eclipse), `Ctrl+D` (Eclipse (macOS))  |
|  删除一行代码  |  `Ctrl+Y` (Windows), `⌘ ⌫` (macOS), `⌘ Y` (IntelliJ IDEA Classic (macOS)), `⌘ ⌫` (macOS System Shortcuts), `Ctrl+Y` (XWin), `Ctrl+Y` (GNOME), `Ctrl+Y` (KDE), `Ctrl+Y` (Emacs), `Ctrl+Shift+K` (Sublime Text), `⌃ ⇧ K` (Sublime Text (macOS)), `Ctrl+L` (Visual Studio), `⌘ ⇧ L` (Visual Studio (macOS)), `Ctrl+E` (NetBeans), `Ctrl+D` (Eclipse), `⌘ D` (Eclipse (macOS))  |
|  注释或取消注释一行代码  |  `Ctrl+/` (Windows), `⌘ /` (macOS), `⌘ /` (IntelliJ IDEA Classic (macOS)), `⌘ /` (macOS System Shortcuts), `Ctrl+/` (XWin), `Ctrl+/` (GNOME), `Ctrl+/` (KDE), `Alt+;` (Emacs), `Ctrl+/` (Sublime Text), `⌘ /` (Sublime Text (macOS)), `Ctrl+Alt+/` (Visual Studio), `⌘ ⌥ /` (Visual Studio (macOS)), `Ctrl+/` (NetBeans), `Ctrl+/` (Eclipse), `⌘ /` (Eclipse (macOS))  |
|  注释一个代码块  |  `Ctrl+Shift+/` (Windows), `⌘ ⌥ /` (macOS), `⌃ ⇧ /` (IntelliJ IDEA Classic (macOS)), `⌘ ⌥ /` (macOS System Shortcuts), `Ctrl+Shift+/` (XWin), `Ctrl+Shift+/` (GNOME), `Ctrl+Shift+/` (KDE), `Ctrl+Shift+/` (Emacs), `Ctrl+Shift+/` (Sublime Text), `⌘ ⌥ /` (Sublime Text (macOS)), `Ctrl+Shift+/` (Visual Studio), `⌘ ⌃ /` (Visual Studio (macOS)), `Ctrl+Shift+/` (NetBeans), `Ctrl+Shift+/` (Eclipse), `⌘ ⇧ /` (Eclipse (macOS))  |
|  在当前打开的文件中查找  |  `Ctrl+F` (Windows), `⌘ F` (macOS), `⌘ F` (IntelliJ IDEA Classic (macOS)), `⌘ F` (macOS System Shortcuts), `Ctrl+F` (XWin), `Ctrl+F` (GNOME), `Ctrl+F` (KDE), `Ctrl+Alt+S` (Emacs), `Ctrl+F` (Sublime Text), `⌘ F` (Sublime Text (macOS)), `Ctrl+F` (Visual Studio), `⌘ F` (Visual Studio (macOS)), `Ctrl+F` (NetBeans), `Ctrl+F` (Eclipse), `Ctrl+F` (Eclipse (macOS))  |
|  在当前文件中查找并替换  |  `Ctrl+R` (Windows), `⌘ R` (macOS), `⌘ R` (IntelliJ IDEA Classic (macOS)), `⌘ R` (macOS System Shortcuts), `Ctrl+R` (XWin), `Ctrl+R` (GNOME), `Ctrl+R` (KDE), `Alt+Shift+5` (Emacs), `Ctrl+H` (Sublime Text), `⌘ ⌥ F` (Sublime Text (macOS)), `Ctrl+H` (Visual Studio), `⌃ H` (Visual Studio (macOS)), `Ctrl+H` (NetBeans), `Ctrl+F` (Eclipse), `Ctrl+R` (Eclipse (macOS))  |
|  下一个匹配项  |  `F3` (Windows), `⌘ G` (macOS), `F3` (IntelliJ IDEA Classic (macOS)), `⌘ G` (macOS System Shortcuts), `F3` (XWin), `F3` (GNOME), `F3` (KDE), `F3` (Emacs), `F3` (Sublime Text), `⌘ G` (Sublime Text (macOS)), `F3` (Visual Studio), `F3` (Visual Studio (macOS)), `F3` (NetBeans), `Ctrl+K` (Eclipse), `⌘ K` (Eclipse (macOS))  |
|  上一个匹配项  |  `Shift+F3` (Windows), `⌘ ⇧ G` (macOS), `⇧ F3` (IntelliJ IDEA Classic (macOS)), `⌘ ⇧ G` (macOS System Shortcuts), `Shift+F3` (XWin), `Shift+F3` (GNOME), `Shift+F3` (KDE), `Shift+F3` (Emacs), `Shift+F3` (Sublime Text), `⌘ ⇧ G` (Sublime Text (macOS)), `Shift+F3` (Visual Studio), `⇧ F3` (Visual Studio (macOS)), `Shift+F3` (NetBeans), `Ctrl+Shift+K` (Eclipse), `⌘ ⇧ K` (Eclipse (macOS))  |
|  在已打开的选项卡之间导航  |  `Alt+Right` (Windows), `⌘ ⇧ ]` (macOS), `⌃ →` (IntelliJ IDEA Classic (macOS)), `⌘ ⌥ →` (macOS System Shortcuts), `Alt+Right` (XWin), `Alt+Right` (GNOME), `Alt+Right` (KDE), `Alt+Right` (Emacs), `Ctrl+Page Down` (Sublime Text), `⌘ ⇧ ]` (Sublime Text (macOS)), `Alt+Right` (Visual Studio), `⌘ ⇧ ]` (Visual Studio (macOS)), `Ctrl+Page Down` (NetBeans), `Ctrl+F6` (Eclipse), `⌘ F6` (Eclipse (macOS)) `Alt+Left` (Windows), `⌘ ⇧ [` (macOS), `⌃ ←` (IntelliJ IDEA Classic (macOS)), `⌘ ⌥ ←` (macOS System Shortcuts), `Alt+Left` (XWin), `Alt+Left` (GNOME), `Alt+Left` (KDE), `Alt+Left` (Emacs), `Ctrl+Page Up` (Sublime Text), `⌘ ⇧ [` (Sublime Text (macOS)), `Alt+Left` (Visual Studio), `⌘ ⇧ [` (Visual Studio (macOS)), `Ctrl+Page Up` (NetBeans), `Ctrl+Shift+F6` (Eclipse), `⌘ ⇧ F6` (Eclipse (macOS))  |
|  后退/前进导航  |  `Ctrl+Alt+Left` (Windows), `⌘ [` (macOS), `⌘ ⌥ ←` (IntelliJ IDEA Classic (macOS)), `⌘ [` (macOS System Shortcuts), `Ctrl+Alt+Left` (XWin), `Alt+Shift+Left` (GNOME), `Ctrl+Alt+Left` (KDE), `Ctrl+Alt+Left` (Emacs), `Alt+NumPad -` (Sublime Text), `⌃ NumPad -` (Sublime Text (macOS)), `Ctrl+Minus` (Visual Studio), `⌘ Minus` (Visual Studio (macOS)), `Alt+Left` (NetBeans), `Alt+Left` (Eclipse), `⌘ [` (Eclipse (macOS)) `Ctrl+Alt+Right` (Windows), `⌘ ]` (macOS), `⌘ ⌥ →` (IntelliJ IDEA Classic (macOS)), `⌘ ]` (macOS System Shortcuts), `Ctrl+Alt+Right` (XWin), `Alt+Shift+Right` (GNOME), `Ctrl+Alt+Right` (KDE), `Ctrl+Alt+Right` (Emacs), `Alt+Shift+NumPad -` (Sublime Text), `⌃ ⇧ NumPad -` (Sublime Text (macOS)), `Ctrl+Shift+Minus` (Visual Studio), `⌘ ⇧ Minus` (Visual Studio (macOS)), `Alt+Right` (NetBeans), `Alt+Right` (Eclipse), `⌘ ]` (Eclipse (macOS))  |
|  在编辑器中展开或折叠代码块  |  `Ctrl+NumPad +` (Windows), `⌘ NumPad +` (macOS), `⌘ NumPad +` (IntelliJ IDEA Classic (macOS)), `⌘ NumPad +` (macOS System Shortcuts), `Ctrl+NumPad +` (XWin), `Ctrl+NumPad +` (GNOME), `Ctrl+NumPad +` (KDE), `Ctrl+NumPad +` (Emacs), `Ctrl+NumPad +` (Sublime Text), `⌘ NumPad +` (Sublime Text (macOS)), `Ctrl+NumPad +` (Visual Studio), `⌘ NumPad +` (Visual Studio (macOS)), `Ctrl+NumPad +` (NetBeans), `Ctrl+Shift+NumPad *` (Eclipse), `⌘ ⇧ NumPad *` (Eclipse (macOS)) `Ctrl+NumPad -` (Windows), `⌘ NumPad -` (macOS), `⌘ NumPad -` (IntelliJ IDEA Classic (macOS)), `⌘ NumPad -` (macOS System Shortcuts), `Ctrl+NumPad -` (XWin), `Ctrl+NumPad -` (GNOME), `Ctrl+NumPad -` (KDE), `Ctrl+NumPad -` (Emacs), `Ctrl+NumPad -` (Sublime Text), `⌘ NumPad -` (Sublime Text (macOS)), `Ctrl+NumPad -` (Visual Studio), `⌘ NumPad -` (Visual Studio (macOS)), `Ctrl+NumPad -` (NetBeans), `Ctrl+Shift+NumPad /` (Eclipse), `⌘ ⇧ NumPad /` (Eclipse (macOS))  |
|  生成  |  `Alt+Insert` (Windows), `⌥ Insert` (macOS), `⌥ Insert` (IntelliJ IDEA Classic (macOS)), `⌥ Insert` (macOS System Shortcuts), `Alt+Insert` (XWin), `Alt+Insert` (GNOME), `Alt+Insert` (KDE), `Alt+Insert` (Emacs), `Alt+Insert` (Sublime Text), `⌥ Insert` (Sublime Text (macOS)), `Alt+Insert` (Visual Studio), `⌥ Insert` (Visual Studio (macOS)), `Alt+Insert` (NetBeans), `Alt+Insert` (Eclipse), `⌥ Insert` (Eclipse (macOS))  |
|  用…包围  |  `Ctrl+Alt+T` (Windows), `⌘ ⌥ T` (macOS), `⌘ ⌥ T` (IntelliJ IDEA Classic (macOS)), `⌘ ⌥ T` (macOS System Shortcuts), `Ctrl+Alt+Shift+B` (XWin), `Ctrl+Alt+Shift+B` (GNOME), `Ctrl+Alt+Shift+B` (KDE), `Ctrl+Alt+T` (Emacs), `Ctrl+Alt+T` (Sublime Text), `⌘ ⌥ T` (Sublime Text (macOS)), `Ctrl+Alt+T` (Visual Studio), `Ctrl+Alt+T` (Visual Studio (macOS)), `Ctrl+Alt+T` (NetBeans), `Alt+Shift+Z` (Eclipse), `⌘ ⌥ Z` (Eclipse (macOS))  |
|  高亮显示符号的用法  |  `Ctrl+F7` (Windows), `⌘ F7` (macOS), `⌘ F7` (IntelliJ IDEA Classic (macOS)), `⌃ ⇧ U` (macOS System Shortcuts), `Ctrl+F7` (XWin), `Ctrl+F7` (GNOME), `Ctrl+7` (KDE), `Ctrl+F7` (Emacs), `Ctrl+F7` (Sublime Text), `⌘ F7` (Sublime Text (macOS)), `Alt+Shift+F11` (Visual Studio), `⌥ ⇧ F11` (Visual Studio (macOS)), `Ctrl+F7` (NetBeans), `Ctrl+Shift+G` (Eclipse), `⌘ ⇧ U` (Eclipse (macOS))  |

要按语法扩展选择，请按 `Ctrl+W` (Windows), `⌥ ↑` (macOS), `⌘ W` (IntelliJ IDEA Classic (macOS)), `⌥ ↑` (macOS System Shortcuts), `Ctrl+W` (XWin), `Ctrl+W` (GNOME), `Ctrl+W` (KDE), `Ctrl+Alt+W` (Emacs), `Ctrl+Shift+Space` (Sublime Text), `⌘ ⇧ A` (Sublime Text (macOS)), `Alt+Shift+=` (Visual Studio), `⌘ ⌥ →` (Visual Studio (macOS)), `Alt+Shift+.` (NetBeans), `Alt+Shift+Up` (Eclipse), `⌃ ⇧ ↑` (Eclipse (macOS))。 要缩小选择，请按 `Ctrl+Shift+W` (Windows), `⌥ ↓` (macOS), `⌘ ⇧ W` (IntelliJ IDEA Classic (macOS)), `⌥ ↓` (macOS System Shortcuts), `Ctrl+Shift+W` (XWin), `Ctrl+Shift+W` (GNOME), `Ctrl+Shift+W` (KDE), `Ctrl+Shift+W` (Emacs), `Ctrl+Shift+W` (Sublime Text), `Ctrl+Shift+W` (Sublime Text (macOS)), `Alt+Shift+Minus` (Visual Studio), `⌘ ⌥ ←` (Visual Studio (macOS)), `Alt+Shift+Comma` (NetBeans), `Alt+Shift+Down` (Eclipse), `⌃ ⇧ ↓` (Eclipse (macOS))。

IntelliJ IDEA 可以同时选择多段代码。 可以通过 `Alt+J` (Windows), `⌃ G` (macOS), `⌃ G` (IntelliJ IDEA Classic (macOS)), `⌃ G` (macOS System Shortcuts), `Alt+J` (XWin), `Alt+J` (GNOME), `Alt+J` (KDE), `Alt+J` (Emacs), `Ctrl+D` (Sublime Text), `⌘ D` (Sublime Text (macOS)), `Alt+Shift+.` (Visual Studio), `⌥ ⇧ .` (Visual Studio (macOS)), `Alt+J` (NetBeans), `Alt+Y` (Eclipse), `⌃ G` (Eclipse (macOS)) 选择下一个匹配项，并按 `Alt+Shift+J` (Windows), `⌃ ⇧ G` (macOS), `⌃ ⇧ G` (IntelliJ IDEA Classic (macOS)), `⌃ ⇧ G` (macOS System Shortcuts), `Alt+Shift+J` (XWin), `Alt+Shift+J` (GNOME), `Alt+Shift+J` (KDE), `Alt+Shift+J` (Emacs), `Alt+Shift+J` (Sublime Text), `⌃ ⇧ G` (Sublime Text (macOS)), `Alt+Shift+Comma` (Visual Studio), `⌥ ⇧ Comma` (Visual Studio (macOS)), `Alt+Shift+J` (NetBeans), `Alt+Shift+Y` (Eclipse), `⌃ ⇧ G` (Eclipse (macOS)) 取消选择。 甚至可以按 `Ctrl+Alt+Shift+J` (Windows), `⌘ ⌃ G` (macOS), `⌘ ⌃ G` (IntelliJ IDEA Classic (macOS)), `⌘ ⌃ G` (macOS System Shortcuts), `Ctrl+Alt+Shift+J` (XWin), `Ctrl+Alt+Shift+J` (GNOME), `Ctrl+Alt+Shift+J` (KDE), `Ctrl+Alt+Shift+J` (Emacs), `Alt+F3` (Sublime Text), `⌘ ⌃ G` (Sublime Text (macOS)), `Alt+Shift+;` (Visual Studio), `⌥ ⇧ ;` (Visual Studio (macOS)), `Ctrl+Alt+Shift+J` (NetBeans), `Ctrl+Alt+Y` (Eclipse), `⌘ ⌃ G` (Eclipse (macOS)) 一次性选择所有匹配项。

有关更多信息，请参见 [编辑器基础](using-code-editor.html)。

使用 IntelliJ IDEA 您无需每次都保存代码更改，因为您可以从 [本地历史记录](local-history.html) 中撤消重构并还原更改。

## Groovy 代码样式和格式化

IntelliJ IDEA 会在您编辑时自动应用您在 [Groovy 代码样式设置](code-style-groovy.html)中配置的代码样式。

![Groovy 代码风格设置](https://resources.jetbrains.com.cn/help/img/idea/2026.3/groovy_code_style_settings.png)

检查以下格式快捷键：

|  操作  |  快捷键  |
| --- | --- |
|  重新格式化代码  |  `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)), `Ctrl+Alt+Enter` (Visual Studio), `⌘ ⌥ ⏎` (Visual Studio (macOS)), `Alt+Shift+F` (NetBeans), `Ctrl+Alt+L` (Eclipse), `⌘ ⇧ F` (Eclipse (macOS))  |
|  自动缩进行  |  `Ctrl+Alt+I` (Windows), `⌃ ⌥ I` (macOS), `⌘ ⌥ I` (IntelliJ IDEA Classic (macOS)), `⌃ ⌥ I` (macOS System Shortcuts), `Ctrl+Alt+I` (XWin), `Ctrl+Alt+I` (GNOME), `Ctrl+Alt+I` (KDE), `Ctrl+Alt+I` (Emacs), `Ctrl+Alt+I` (Sublime Text), `⌃ ⌥ I` (Sublime Text (macOS)), `Ctrl+Alt+I` (Visual Studio), `⌃ ⌥ I` (Visual Studio (macOS)), `Ctrl+Alt+I` (NetBeans), `Ctrl+I` (Eclipse), `⌘ I` (Eclipse (macOS))  |
|  优化导入  |  `Ctrl+Alt+O` (Windows), `⌃ ⌥ O` (macOS), `⌘ ⌥ O` (IntelliJ IDEA Classic (macOS)), `⌃ ⌥ O` (macOS System Shortcuts), `Ctrl+Alt+O` (XWin), `Ctrl+Alt+O` (GNOME), `Ctrl+Alt+O` (KDE), `Ctrl+Alt+O` (Emacs), `Ctrl+Alt+O` (Sublime Text), `⌃ ⌥ O` (Sublime Text (macOS)), `Ctrl+R, G` (Visual Studio), `⌃ ⌥ O` (Visual Studio (macOS)), `Ctrl+Shift+I` (NetBeans), `Ctrl+Alt+O` (Eclipse), `⌘ ⇧ O` (Eclipse (macOS))  |

请注意，默认情况下，IntelliJ IDEA 使用常规空格而不是制表符进行缩进。 如果文件包含大量缩进，可以启用位于  `设置 | 编辑器 | 代码样式 | Groovy`  中的   使用制表符   选项来优化其大小。

如需更多信息，请参阅 [Reformatting Source Code](reformat-and-rearrange-code.html)。

## See also

### 外部链接

[Groovy documentation](http://www.groovy-lang.org/single-page-documentation.html)

