是否有 Eclipse 线宽标记?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1248895/
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
Is there an Eclipse line-width marker?
提问by Mocky
I have a specific project where I need to wrap every code line at 65 characters. I have set up the eclipse Java code formatter properly for this. But what I really want is a vertical line to be drawn in the editor showing where the max line width while I am typing, not just when I run the formmater. I know this feature is available in some capacity because it is displayed in the code formatter property page.
我有一个特定的项目,我需要将每个代码行包装成 65 个字符。我已经为此正确设置了 Eclipse Java 代码格式化程序。但我真正想要的是在编辑器中绘制一条垂直线,显示我打字时的最大线宽,而不仅仅是在我运行 formmater 时。我知道此功能在某些情况下可用,因为它显示在代码格式化程序属性页中。
I don't see any option in eclipse to turn this on and I didn't see any plug-ins that do it on Eclipse Plugin Central
我在 Eclipse 中没有看到任何选项可以打开它,也没有在 Eclipse Plugin Central 上看到任何插件
回答by Jon Skeet
Look in Windows / Preferences (at least on Windows - IIRC it moves around for different operating systems) then:
查看 Windows / 首选项(至少在 Windows 上 - IIRC 它针对不同的操作系统移动)然后:
General -> Editors -> Text Editors -> Show Print Margin
Tick this and it should show the line.
勾选此项,它应该显示该行。
As a quick way of finding this, use the search filter in the top and filter on "margin".
作为快速找到它的方法,使用顶部的搜索过滤器并过滤“边距”。
Notes from the comments - unverified by me, but I have no reason to doubt them:
评论中的注释 - 未经我证实,但我没有理由怀疑它们:
It has changed somehow in 2016: For details see [here] (https://bugs.eclipse.org/bugs/show_bug.cgi?id=495490#c2) You have to set it in the formatter: From menu [Window]-->[Preferences], select [Java]-->[Code Style]-->[Formatter], and then edit your formatter profile. In the tab page [Line wrapping], you can find a setting named "Maximum line width". Change this setting, and the print margin in Java source editor will be changed too.
它在 2016 年发生了某种变化:有关详细信息,请参见 [此处] ( https://bugs.eclipse.org/bugs/show_bug.cgi?id=495490#c2) 您必须在格式化程序中进行设置:从菜单 [Window] -->[首选项],选择[Java]-->[代码样式]-->[格式化程序],然后编辑您的格式化程序配置文件。在【换行】标签页中,可以找到一个名为“最大线宽”的设置。更改此设置,Java 源代码编辑器中的打印边距也会更改。
回答by Do Nhu Vy
In Eclipse Luna (4.4):
Choose menu Window\Preference
. Look at top-left corner, in search box type filter text
, type: margin
.
In section Apperance color option
, Choose Print margin
. Choose Show print margin
. In text box Print margin column
, type 65
as what you want.
在 Eclipse Luna (4.4) 中:选择 menu Window\Preference
。查看左上角,在搜索框中type filter text
,键入:margin
。
在部分中Apperance color option
,选择Print margin
。选择Show print margin
。在文本框中Print margin column
,键入65
您想要的内容。
回答by Gabriel Staples
@Jon Skeet's answeris incomplete.
@Jon Skeet 的回答不完整。
(1/2) First, do what he said:
(1/2) 首先,按他说的做:
Window
--> Preferences
--> General
--> Editors
--> Text Editors
--> check the box for Show Print Margin
Window
--> Preferences
--> General
--> Editors
--> Text Editors
--> 勾选Show Print Margin
Ticking this box will show the vertical line.
勾选此框将显示垂直线。
As a quick way of finding this, use the search filter in the top and filter on "margin".
作为快速找到它的方法,使用顶部的搜索过滤器并过滤“边距”。
However, this only shows the line, but under most situations the "Print margin column" value there is flat-out ignored.
但是,这仅显示该行,但在大多数情况下,“打印边距列”值会被完全忽略。
To set the column number for where the line should be, do what @John Percival Hackworth mentions here:
要设置该行所在位置的列号,请执行@John Percival Hackworth在此处提到的操作:
(2/2) Go to:
(2/2) 前往:
Window
--> Preferences
--> C/C++
[or whatever language you are using] --> Code Style
--> Formatter
--> click Edit
--> under the Line Wrapping
tab set the value you desire for Maximum line width
.
Window
--> Preferences
--> C/C++
[或您使用的任何语言] --> Code Style
--> Formatter
--> 单击Edit
--> 在Line Wrapping
选项卡下设置您想要的值Maximum line width
。
Side note:
边注:
- Use Alt+ Shift+ Yto toggle soft line wrapping on and off. It will soft wrap (ie: no carriage return) at the end of the screen, however, not at the column you set above.
- 使用Alt+ Shift+Y开启和关闭软换行。它将在屏幕末尾软换行(即:不回车),但是,不会在您上面设置的列中。
How do you enforce hard line wrapping at the column you set above (ie: that adds a carriage return)? I don't know yet.If you figure it out let me know. In Sublime Text 3 (a much better editor but with a much worse indexer/function definition finder :() it's Alt+ Q.
您如何在上面设置的列中强制强制换行(即:添加回车符)?我还不知道。如果你弄清楚了,请告诉我。在 Sublime Text 3(一个更好的编辑器,但索引器/函数定义查找器更糟糕:() 它是Alt+ Q.
Update:I think it may be possible with the "CppStyle" plugin, which uses clang-format
, by using Ctrl+ Shift+ Fto apply the auto-format, but I don't know the exact instructions to make it work yet.
更新:我想这可能与“CppStyle”插件,它的用途clang-format
,使用Ctrl+ Shift+F应用自动格式,但我不知道确切的指令,使其工作还没有。
Related:
有关的:
- Set tab width: Changing editor tab width in eclipse 3.5
- 设置选项卡宽度:在 Eclipse 3.5 中更改编辑器选项卡宽度