gpt4 book ai didi

eclipse - Eclipse 中的多行字符串对齐/缩进

转载 作者:行者123 更新时间:2023-12-02 15:19:39 32 4
gpt4 key购买 nike

我正在使用 Eclipse Luna,并且想要对齐/缩进多行字符串文字,以便每一行都从同一列开始。但我很难说服 Eclipse 在代码样式格式化程序中执行此操作。

这就是当前的格式:

    final String string1 =
"abc" +
"def" +
"ghi";

System.out.println(
"abc" +
"def" +
"ghi");

System.out.println("" + // an ugly workaround
"abc" +
"def" +
"ghi");

method("xyz",
"" + // Especially ugly in this case
"abc" +
"def" +
"ghi");

但这才是我真正想要的:

    final String string2 =
"abc" +
"def" +
"ghi";

System.out.println(
"abc" +
"def" +
"ghi");

// Or something like this would be fine too
final String string3 =
"abc"
+ "def"
+ "ghi";

System.out.println(
"abc"
+ "def"
+ "ghi");

这似乎是一种简单而理想的格式。只需在同一列上开始分解线的每个部分即可。但我一直没能找到一种方法来做到这一点。

最佳答案

以下设置适用于您的前两个示例。将您的示例复制粘贴到 block 中,然后重新格式化。但是,使用此设置时,您需要手动换行,格式化程序将缩进它们并防止连接它们。您可能需要调整其他设置,因为“换行的默认缩进”为 0。

换行下:

  1. 选中“切勿加入已换行的行”

  2. 将“换行的默认缩进:”设置为 0

  3. 表达式/赋值:

    • 必要时换行,
    • 缩进一位
  4. 表达式/二进制表达式:

    • 必要时包裹起来,
    • 在运算符(operator)之前检查 Wrap,
    • 默认缩进

还有一个选项可以禁用格式化程序,然后在您想要手动格式化的代码之后重新启用它。当您想要格式化初始值设定项中的表格数据以提高可读性时,这会很有用。这位于格式化程序设置中的“关闭/打开标签”下。

关于eclipse - Eclipse 中的多行字符串对齐/缩进,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36458035/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com