简体   繁体   English

在 VSCode Java 格式化程序中保留换行符

[英]Preserving line breaks in VSCode Java formatter

I am currently using Java in Visual Studio Code , and I am having a problem with formatting.我目前在Visual Studio Code中使用Java ,但我遇到了格式问题。

I want to preserve the line breaks I made on purpose even after formatting.即使在格式化后,我也想保留我故意制作的换行符。

BUT VSCode doesn't allows me to do that.但是VSCode不允许我这样做。

Is there a solution for this problem?这个问题有解决方案吗?

[Before formatting] [格式化前]

someClass.someMethod(
        veryLongParameterOne,
        veryLongParameteTwo,
        veryLongParameterThree
);

[After formatting] [格式化后]

someClass.someMethod(
        veryLongParameterOne,
        veryLongParameteTwo,
        veryLongParameterThree);

All I want is to keep the code the same before and after formatting.我想要的只是在格式化之前和之后保持代码相同。

  1. You can use some special comment to let the extension skip format in a range:您可以使用一些特殊的注释让扩展在一个范围内跳过格式:
//@formatter:off
someClass.someMethod(
        veryLongParameterOne,
        veryLongParameteTwo,
        veryLongParameterThree
);
//@formatter:on
  1. Or you can trigger a command Java: Open Java Formatter Settings with Preview to view some basic format settings in UI.或者您可以触发命令Java: Open Java Formatter Settings with Preview以查看 UI 中的一些基本格式设置。 Meanwhile it will generate a .xml format profile in .vscode folder, in which you can find all format settings there.同时它将在 .vscode 文件夹中生成一个 .xml 格式配置文件,您可以在其中找到所有格式设置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM