You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何配置IntelliJ,使格式化时自动在return前插入空行?

配置IntelliJ代码格式化:在return语句前自动插入空白行

能否配置IntelliJ,使其在使用Ctrl + Alt + L快捷键格式化代码时,自动在return语句前插入空白行?

当前代码样式:

public static String getValue() {
    String some = "a";
    String another = "bb";
    return some;
}

期望格式化后的样式:

public static String getValue() {
    String some = "a";
    String another = "bb";

    return some;
}

具体配置步骤

  • 打开IntelliJ设置界面:通过File > Settings(Windows/Linux)、IntelliJ IDEA > Settings(Mac),或快捷键Ctrl + Alt + S(Windows/Linux)、Cmd + ,(Mac)打开。
  • 在设置窗口中,依次进入Editor > Code Style > Java(若为其他编程语言,选择对应语言项)。
  • 切换至Wrapping and Braces标签页,找到Blank Lines分组。
  • 找到Before 'return' statement选项,将其值设置为1。
  • 点击Apply和OK保存配置。

完成配置后,使用Ctrl + Alt + L格式化代码,return语句前就会自动插入一行空白。

内容的提问来源于stack exchange,提问作者lamcpp

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.22 09:33:12