在 IntelliJ 中仅格式化选定的代码块

Ani*_*mar 8 intellij-idea

是否可以仅格式化选定的代码块。我只能用 IntelliJ 格式化整个文件或整个项目。我在 MacOS 上使用社区版 2017.2。

byx*_*xor 6

IntelliJ IDEA 帮助(重新格式化文件对话框)

  1. 突出显示代码块。

  2. 打开Reformat File对话框:

    • 苹果机:Shift+ ?+ ?+L
    • Windows/Linux: Ctrl+ Alt+ Shift+L
  3. 单击“选定文本”单选按钮。

  4. 单击“运行”按钮。

它应该是这样的:

重新格式化文件对话框的想象

  • 只要选择相关代码,只需“Ctrl+Alt+L”即可完成这项工作,而无需显示此对话框。[Intellij 文档](https://www.jetbrains.com/help/idea/reformat-and-rearrange-code.html#reformat_code) (3认同)

Mak*_*oto 3

是的; 只需通过键盘或菜单突出显示代码块并对其进行格式化即可。其格式化方式以及格式化内容仅由您的格式化首选项决定。