Eclipse:自动换行到指定宽度
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9241973/
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
Eclipse: Automatic line wrapping to specified width
提问by Steven Lu
I'd like for my lines, especially within comments, to be automatically managed so they don't get too long.
我希望我的台词,特别是在评论中,自动管理,这样它们就不会太长。
I remember once I had a configuration for vim
which automatically moved the word I was typing to the next line once I reached 72 characters. It wasn't smart enough to rearrange the paragraph if I edit it, but it was a start.
我记得有一次我有一个配置,vim
当我输入 72 个字符时,它会自动将我正在输入的单词移动到下一行。如果我编辑它,重新排列段落还不够聪明,但这是一个开始。
Is there something that can manage these for me? I have a tendency to write really long comments in my code, and it helps to make them look neat by having consistent width, but it's always a pain to do this because oftentimes editing a sentence requires editing the entire rest of the paragraph.
有什么可以为我管理这些的吗?我倾向于在我的代码中写很长的注释,通过一致的宽度使它们看起来很整洁,但这样做总是很痛苦,因为通常编辑一个句子需要编辑整个段落的其余部分。
I have just recently discovered the Ctrl+Shift+Ffeature. It is amazing and superior to Ctrl+Iwhich is what I was using up till now, but I noticed that it does not do anything to clean up my comments.
我最近刚发现的Ctrl+ Shift+F功能。它是惊人的,优于Ctrl+I这是我到现在为止一直使用的,但我注意到它没有做任何事情来清理我的评论。
Update: The answers are correct when working with Java in Eclipse. It seems like I have to wait for the CDT to incorporate this feature.
更新:在 Eclipse 中使用 Java 时,答案是正确的。看来只能等CDT加入这个功能了。
回答by Baldrick
In "Windows -> Preferences", go to "Java -> Code style -> Formatter" to customize the formatter (called when you click Ctrl+Shift+F). In the tab "comment", you can set the maximum line width for comments (it can be different then the line width for code).
在“Windows -> Preferences”中,进入“Java -> Code style -> Formatter”自定义格式化程序(点击Ctrl+ Shift+时调用F)。在“注释”选项卡中,您可以设置注释的最大行宽(它可以与代码的行宽不同)。
Tip: in the preferences, "Java -> Editor -> Save actions", you can make Eclipse to automatically format your file when you save it, so your code is always correctly indented !
提示:在首选项中,“Java -> Editor -> Save actions”,您可以让 Eclipse 在您保存文件时自动格式化您的文件,因此您的代码始终正确缩进!
回答by Robert
The automatic formatting of Eclipse great no question.
Eclipse 的自动格式化很棒毫无疑问。
If your comments are reformatted depends on what comment type and how you already have inserted line breaks.
如果您的评论重新格式化取决于什么评论类型以及您已经如何插入换行符。
Writing for example one very long line comment starting with //
will be broken down by the formatter into multiple lines.
例如,以 开头的一个很长的行注释//
将被格式化程序分解为多行。
However you later edit the formatted lines - e.g. delete parts of it the formatter will leave them as they are. Only over-long lines will be changed.
但是,您稍后编辑格式化的行 - 例如删除其中的一部分,格式化程序将保留它们原样。只会更改过长的行。
Just in difference to block comments like this: /* comment */
Those comments will always be re-formatted in case the line is too short or too long.
不同之处在于阻止这样的评论:/* comment */
如果行太短或太长,这些评论将始终重新格式化。
回答by Line
If you want to format your header comment, you have to check Enable header comment formatting- that was the trick for me.
如果你想格式化你的标题评论,你必须选中启用标题评论格式- 这对我来说是诀窍。
Obviously, to use this, you must create new formatter profile.
显然,要使用它,您必须创建新的格式化程序配置文件。