Eclipse 自动格式化程序,禁用注释行的自动换行

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9645322/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 17:49:00  来源:igfitidea点击:

Eclipse auto-formatter, disable auto line-wrapping of comment lines

eclipseautoformatting

提问by Gal

I love eclipse auto formatting, but there's one feature that's driving me raging mad:

我喜欢 eclipse 自动格式化,但有一个功能让我发疯:

Since I use wrap-lines in my auto-formmatter, code like this:

由于我在自动格式化程序中使用换行,因此代码如下:

private static Location                         _location           = null; // this is a comment

turns into horrible, horrible code like this:

变成了像这样可怕的、可怕的代码:

private static Location                         _location           = null;                 // this
                                                                                                    // is
                                                                                                    // a
                                                                                                    // comment

this is not only painful to watch, but not at all convenient to change back...

这不仅看着很痛苦,而且换回来一点也不方便......

Is there any way to remove line-wrapping for comments, or at least fix so it doesn't look like an absolute mess?

有什么方法可以删除注释的换行符,或者至少修复它,使其看起来不像绝对一团糟?

Thanks

谢谢

回答by Boris Strandjev

I think that the thing you are specifically asking about you can achieve by editing your formatter:

我认为您特别询问的事情可以通过编辑格式化程序来实现:

  • Window-> Preferences-> Java-> Code Style-> Formatter. There edit you click on Edit...
  • If you are using the default Eclipse formatter you will need to edit the profile name (you cna not edit built in profile).
  • Go to comments
  • Deselect line comment formatting.
  • Window-> Preferences-> Java-> Code Style-> Formatter。你点击编辑Edit...
  • 如果您使用默认的 Eclipse 格式化程序,您将需要编辑配置文件名称(您不能编辑内置配置文件)。
  • 去评论
  • 取消选择行注释格式。

That way no formatting of comments of the type //will be done.

这样就不//会对类型的注释进行格式化。

回答by David

This annoys me also. To fix the wrapped comments you can use the keyboard shortcut CTL+ALT+J to join the comments onto one line. The comment-indicator characters (// or *) will still be there but at least it will save you some steps. Then you can just run a find and replace for the comment-indicators.

这也让我很恼火。要修复包装的注释,您可以使用键盘快捷键 CTL+ALT+J 将注释合并到一行。注释指示符(// 或 *)仍然存在,但至少可以为您节省一些步骤。然后,您可以运行查找和替换注释指示符。