如何防止 Eclipse 在 XML 和 HTML 文件中换行?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2005929/
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
Howto prevent eclipse from line wrapping in XML and HTML files?
提问by c0d3x
Is it possible to completely stop Eclipse from line wrapping XML and HTML files? It is easy to do this i.e. for java files, but I couldn't find similar settings for XML and HTML files.
是否可以完全阻止 Eclipse 对 XML 和 HTML 文件进行换行?很容易做到这一点,即对于 java 文件,但我找不到 XML 和 HTML 文件的类似设置。
采纳答案by VonC
Note: the word/line wrapping in eclipse is a "sore" topic, since 2003, as this massively voted bug 35779
注意:自 2003 年以来,eclipse 中的字/行换行是一个“痛苦”的话题,因为这个被大量投票的错误 35779
As Bozhomentions, there is only hard-wrapping(at a specify length)
alt text http://www.openengsb.org/images/codingstyle/eclipse-xml-settings.png
替代文字 http://www.openengsb.org/images/codingstyle/eclipse-xml-settings.png
Reminder:
提醒:
Softwill just warp the text at the right window border without adding new line numbers (so there are gaps in the list of numbers when you enable them).
This mode is useful for HTML and the like.
A nice feature of the soft wrap is automatic indentation: If there is whitespace at the beginning of the line, the wrapped lines are automatically indented by the same amount.Hardwill add and remove newlines in the text as you type to balance the width.
Here, you can usually set a margin (80 characters, for example).
This is useful for READMEs and other stuff that will be read in a terminal.
Soft只会在右侧窗口边框处扭曲文本,而不会添加新的行号(因此当您启用它们时,数字列表中会有间隙)。
这种模式对于 HTML 等很有用。
软换行的一个很好的特性是自动缩进:如果行首有空格,换行的行会自动缩进相同的数量。Hard将在您键入时添加和删除文本中的换行符以平衡宽度。
在这里,您通常可以设置边距(例如 80 个字符)。
这对于将在终端中读取的自述文件和其他内容很有用。
回答by Bozho
Preferences > XML > XML Files > Editor
, and set line-width
there
(Do accordingly for HTML, under Web > HTML files
)
Preferences > XML > XML Files > Editor
, 并在line-width
那里设置(对 HTML 执行相应的操作,在 下Web > HTML files
)
回答by Agustí Sánchez
Yes, the settings for XML formatting are in the IDE-wide preferences tab and apparently they cannot be set on a per-project basis.
是的,XML 格式的设置在 IDE 范围的首选项选项卡中,显然它们不能在每个项目的基础上设置。
I want to point out that what is really annoying is the wrapping of "free text" between elements like in:
我想指出,真正令人讨厌的是在元素之间包装“自由文本”,例如:
<element>some free text</element>
<element>some free text</element>
That's really an inconvenience when dealing with the pattern format in logback.xml files, for instance.
例如,在处理 logback.xml 文件中的模式格式时,这确实很不方便。
I just found out that Eclipse won't format that bit if I enclose the text between <![CDATA[..]]>
.
For instance:
我刚刚发现如果我将文本括在<![CDATA[..]]>
. 例如:
<pattern><![CDATA[%d{HH:mm:ss.SSS} [%thread] [%X{host}|%X{ip}|%X{user}] %-5level %logger{36} - %msg%n]]></pattern>
<pattern><![CDATA[%d{HH:mm:ss.SSS} [%thread] [%X{host}|%X{ip}|%X{user}] %-5level %logger{36} - %msg%n]]></pattern>
Just wanted to share that.
只是想分享一下。