在 Eclipse 3.5 中更改编辑器选项卡宽度
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1650652/
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
Changing editor tab width in eclipse 3.5
提问by Neil
I am trying to adjust the width of tabs from Window -> Preferences -> General -> Editors -> Text Editors where there is a field for "Display Tab Width". But no matter what I enter there the size of indentations when I start a newline in a Java file is 4. Any ideas?
我正在尝试从“窗口”->“首选项”->“常规”->“编辑器”->“文本编辑器”调整选项卡的宽度,其中有一个“显示选项卡宽度”字段。但是无论我输入什么,当我在 Java 文件中开始换行时,缩进的大小都是 4。有什么想法吗?
回答by Neil
Java files have a special place to edit this setting. You need to go to
Java 文件有一个特殊的地方可以编辑此设置。你需要去
Window -> Preferences -> Java -> Code Style -> Formatter
Window -> Preferences -> Java -> Code Style -> Formatter
And edit the profile.
并编辑个人资料。
回答by irudyak
Changing Window -> Preferences -> General -> Editors -> Text Editors tab preference is relevant for text files, not for java files as indicated here. You may create a text file in Eclipse and check that your tab size is really changed.
更改窗口 -> 首选项 -> 常规 -> 编辑器 -> 文本编辑器选项卡首选项与文本文件相关,而不是与此处所示的 java 文件相关。您可以在 Eclipse 中创建一个文本文件并检查您的标签大小是否真的改变了。
回答by Jonathan Feinberg
Check your Java->Code Style->Formatter settings, to see whether you're using tabs or spaces; you might be using spaces!
检查您的 Java->Code Style->Formatter 设置,看看您使用的是制表符还是空格;您可能正在使用空格!
回答by David Pierre
This setting is superseded for Java by the setting from the Code Style Formatter.
对于 Java,此设置被 Code Style Formatter 中的设置所取代。
It can be found in Java / Code Style / Formatter (click Edit) / Indentation tab / Indentation
它可以在 Java / Code Style / Formatter (单击 Edit) / Indentation tab / Indentation 中找到
回答by Sridhar Sarnobat
After digging into this more deeply, I think I've figured this out:
在深入研究之后,我想我已经弄清楚了:
Java file tab DISPLAY width
Java 文件选项卡显示宽度
Confusingly, this is under "Formatter" in preferences (like the accepted answer says). But this is inconsistent location-wise with where the option for tab display width for the non-java file Editor is located.
令人困惑的是,这是在首选项中的“格式化程序”下(就像接受的答案所说的那样)。但这与非 java 文件编辑器的选项卡显示宽度选项所在的位置不一致。
/instance/org.eclipse.jdt.core/org.eclipse.jdt.core.formatter.indentation.size=16
/instance/org.eclipse.jdt.core/org.eclipse.jdt.core.formatter.indentation.size=16
Text file tab DISPLAY width
文本文件选项卡显示宽度
/instance/org.eclipse.ui.editors/tabWidth=2
/instance/org.eclipse.ui.editors/tabWidth=2
I emphasize DISPLAY because this is just for rendering in Eclipse. It does not change the contents of your file, and has no effect on "Source -> Format".
我强调 DISPLAY 因为这只是为了在 Eclipse 中渲染。它不会更改文件的内容,也不会影响“源 -> 格式”。
回答by Gabriel Staples
How to set tab size (number of spaces when you press Tab) in Eclipse or Eclipse CDT:
如何Tab在 Eclipse 或 Eclipse CDT 中设置选项卡大小(按 时的空格数):
There are multiple places to check and things to do:
有多个地方需要检查和要做的事情:
- Global Preferences:
- Window --> Preferences --> General --> Editors --> Text Editors--> change "Displayed tab width" from 4 to 2
- Window --> Preferences --> Java OR C/C++ [depending on which you're using] --> Code Style --> Formatter--> click "Edit" button for your "Active profile" --> click "Indentation" tab on top-left --> change "Indentation size" to 2, "Tab size" to 2, and "Tab policy" to "Spaces only".
- Project Preferences (these override the global settings for a given project):
- Project --> Properties(or just right-click on project in the folder list at the left, and go to "Properties") --> Java OR "C/C++ General" [depending on what you're using] --> Formatter--> either uncheck the box for "Enable project specific settings", OR check that box and ensure your settings are correct (refer to 1.2 above, beginning with the
click "Edit" button
step, but do it from this menu this time).
- Project --> Properties(or just right-click on project in the folder list at the left, and go to "Properties") --> Java OR "C/C++ General" [depending on what you're using] --> Formatter--> either uncheck the box for "Enable project specific settings", OR check that box and ensure your settings are correct (refer to 1.2 above, beginning with the
- To test your new settings: return to your editor and press Enterwith the cursor sitting immediately after an opening curly brace (
{
) somewhere. It should go to a new line with the proper indentation you've set above.- NB: watch out! If you press Enteron or after a line with different indentation from what you've set above, it will duplicate that wrong indentation (by copying the style of the lines just above) rather than accepting your new indentation settings. Do NOT think it isn't working in this case! It IS working! Just delete all of the old indentation and press Enterright after a
{
and you'll see everything works just fine.
- NB: watch out! If you press Enteron or after a line with different indentation from what you've set above, it will duplicate that wrong indentation (by copying the style of the lines just above) rather than accepting your new indentation settings. Do NOT think it isn't working in this case! It IS working! Just delete all of the old indentation and press Enterright after a
- 全局偏好:
- 窗口 --> 首选项 --> 常规 --> 编辑器 --> 文本编辑器--> 将“显示的标签宽度”从 4 更改为 2
- 窗口 --> 首选项 --> Java 或 C/C++ [取决于您使用的] --> 代码样式 --> 格式化程序--> 单击“活动配置文件”的“编辑”按钮 --> 单击“左上角的“缩进”选项卡 --> 将“缩进大小”更改为 2,将“制表符大小”更改为 2,将“制表符策略”更改为“仅空格”。
- 项目首选项(这些会覆盖给定项目的全局设置):
- 项目 --> 属性(或在左侧文件夹列表中右键单击项目,然后转到“属性”)--> Java 或“C/C++ 常规”[取决于您使用的内容]- > Formatter--> 要么取消选中“启用项目特定设置”框,要么选中该框并确保您的设置正确(请参阅上面的 1.2,从该
click "Edit" button
步骤开始,但这次从该菜单执行)。
- 项目 --> 属性(或在左侧文件夹列表中右键单击项目,然后转到“属性”)--> Java 或“C/C++ 常规”[取决于您使用的内容]- > Formatter--> 要么取消选中“启用项目特定设置”框,要么选中该框并确保您的设置正确(请参阅上面的 1.2,从该
- 要测试您的新设置:返回到您的编辑器,然后Enter将光标
{
放在某个位置的左花括号 ( )之后立即按下。它应该使用您在上面设置的正确缩进换到一个新行。- 注意:小心!如果您按Enter与上面设置的缩进不同的行上或之后,它将复制错误的缩进(通过复制上面行的样式)而不是接受新的缩进设置。不要认为它在这种情况下不起作用!这是工作!只需删除所有旧的缩进并Enter在 a 之后按
{
,您会看到一切正常。
- 注意:小心!如果您按Enter与上面设置的缩进不同的行上或之后,它将复制错误的缩进(通过复制上面行的样式)而不是接受新的缩进设置。不要认为它在这种情况下不起作用!这是工作!只需删除所有旧的缩进并Enter在 a 之后按
Version tested:All tested in Eclipse IDE for C/C++ Developers, Version: Oxygen.3a Release (4.7.3a).
测试版本:全部在 Eclipse IDE 中为 C/C++ 开发人员测试,版本:Oxygen.3a Release (4.7.3a)。
Duplicate or Related Questions & Answers:
重复或相关的问题和答案:
- Google search for "Eclipse change tab size" - https://www.google.com/search?q=eclipse+change+tab+size&oq=eclipse+change+&aqs=chrome.0.69i59l3j0l3.2483j0j4&sourceid=chrome&ie=UTF-8
- https://superuser.com/questions/462221/how-do-i-reliably-change-the-indentation-width-in-eclipse
- Eclipse tab width not changing
- 谷歌搜索“Eclipse 更改标签大小” - https://www.google.com/search?q=eclipse+change+tab+size&oq=eclipse+change+&aqs=chrome.0.69i59l3j0l3.2483j0j4&sourceid=chrome&ie=UTF-8
- https://superuser.com/questions/462221/how-do-i-reliably-change-the-indentation-width-in-eclipse
- Eclipse 标签宽度没有改变
Also Related
也相关
- Set line width vertical bar marker / print margin - Is there an Eclipse line-width marker?
- 设置线宽垂直条标记/打印边距 -是否有 Eclipse 线宽标记?