Eclipse 中可以自动缩进吗?

发布于 2024-07-30 09:27:11 字数 286 浏览 5 评论 0原文

我绞尽脑汁试图弄清楚这一点。 前几天我第一次使用 jEdit,我很惊喜地发现它自动缩进了我的代码(这意味着我输入了以下代码:

int method () {
    _ //<-- and it put me here automatically

我试图在 Eclipse 中实现同样的功能,但没有成功。我进入了代码格式化程序,但我不知道如何做到这一点

?另外,当我在这里时,是否有一个 Eclipse 插件可以让您搜索方法和标准java库的类

I have been wracking my brain trying to figure this out. For the first time I used jEdit the other day and I was pleasantly surprised that it auto indented my code (meaning that I'd put in the following code:

int method () {
    _ //<-- and it put me here automatically

I've tried to get the same thing working with eclipse but with no success. I got into the code formatter but I don't see how to make that happen.

Is it possible to do this? Also while I'm here, is there a such thing as a eclipse plugin that will allow you to search the methods and classes of the standard java library?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

故乡的云 2024-08-06 09:27:11

就个人而言,我为此使用的是格式选项“窗口”->“Java”下的“首选项”->“代码样式”->“格式化程序”。

我曾经花时间调整我喜欢的代码在工作时的样子并导出整个代码。 之后我就只是编写代码,而不必过多关注它的外观。 当我发现按组合键 ctrl+shift+f 代码看起来很混乱时,整个类又变得漂亮了,注释等等。

一段时间后,它几乎变成了一种反射......

代码代码代码

ctrl-s,ctrl-b(因为我有时禁用自动构建),ctrl-shift-f

代码更多等等......

一旦我习惯了这个我我从来没有真正关心它如何在我输入时呈现代码,因为我知道一旦循环/if/switch/方法等完成,它就会看起来很漂亮

Personally all I use for this is the format options Window->preferences under Java->Code Style ->Formatter.

I once took the time to tweek how I like my code to look like when I work and exported the whole thing. After that I just code without too much bother on what it looks like. When I find the code looks messy by pressing the combination ctrl+shift+f and the whole class becomes pretty again, comments and all.

After a while it pretty much became a reflex...

code code code

ctrl-s, ctrl-b (cause I disable auto build sometimes), ctrl-shift-f

code some more etc...

Once I got used to this I never really cared how it presented the code as i was typing because I knew it would look all pretty as soon as the loop/if/switch/method etc is finished

╰◇生如夏花灿烂 2024-08-06 09:27:11

我的干净 Eclipse 安装默认执行此操作。

您更改过任何选项吗? 确保您正在编辑的文件具有 .java 文件扩展名。 控制输入​​自动化的首选项位于 Java -> 下。 编辑-> 在窗口中输入 -> 首选项菜单。

另外,我发现如果我正在编辑的文件中存在阻止编译的错误,则 Eclipse 的自动缩进和大多数其他自动完成功能将无法正常工作。 确保你的花括号正确匹配,这是我注意到的阻止自动缩进的主要花括号。

关于搜索标准 Java 库,请使用 Search -> Java.. 菜单选项,并选中 JRE 库复选框,然后搜索即可。 您还可以使用层次结构视图来查看类之间的关系。 此外,在 Package 和 Project 视图中,您可以展开 JRE System Library,然后展开 rt.jar,其中包含几乎所有标准 Java 包。

My clean eclipse install does this by default.

Have you changed any options? Make sure the file you are editing has the .java file extension. The preference options that control the typing automations are under Java -> Editor -> Typing in the Window -> Preferences menu.

Also, I find that the auto-indenting, and most of the other auto-complete functions of eclipse do not function well if the file I am editing has errors in it which prevent compilation. Make sure that your curly-braces are matched correctly, this is the main one that I've noticed blocks auto-indent.

Regarding searching through the standard Java libraries, use the Search -> Java.. menu option, and check the JRE libraries checkbox, then search away. You can also use the Hierarchy view to see how the classes relate. Also, in the Package and Project views you can expand the JRE System Library, and then expand rt.jar which holds pretty much all the standard Java pacakges.

吾家有女初长成 2024-08-06 09:27:11

Eclipse 总是默认为我做这件事。

Eclipse 的一件非常酷的事情是您可以搜索首选项页面。 只需右键单击并转到首选项。 转到“窗口”菜单,然后单击“首选项”。 然后在树视图的顶部有一个文本框,上面写着“键入过滤器文本”。 将其替换为“缩进”,它应该会显示缩进选项所在的页面。

确保 eclipse 将您的文件识别为 java 文件,您使用的是 Java 发行版、最新版本等。

Eclipse has always done this for me by default.

One really cool thing about eclipse is that you can search preference pages. Just right click and go to prefrences. Go to the "Window" menu, and click "Prefrences". Then at the top of the tree view there's a text box that says "type filter text". Replace that with "indent" and it should bring up the page where the indent option is.

Make sure that eclipse recognizes your file as a java file, that you're using the Java distribution, the latest version, etc.

复古式 2024-08-06 09:27:11

多年来我一直在尝试解决日食缩进和其他假定的功能,似乎底线是这样的......
它仅适用于作者的编程风格,因此要使用它,您需要修改您的风格以符合。
除了 eclipse 的作者对常用快捷键有一些非常奇怪的想法之外,这还可以。
一个可怕的例子是搜索功能,例如 Ctrl+K 何时变成“查找下一个出现的位置”以及为什么 F3 或 n 不起作用?
话虽这么说,我使用 eclipse 是因为如果您有时间在它启动时等待 - 或者从不关闭它 - 并且您可以修改您学到的有关使用编辑器的所有内容 - 为什么为什么为什么 - 那么它肯定会提高您的效率。
请注意,缩进有一个首选项设置,它可以为项目、工作区或全局设置,但无论您如何设置,Eclipse 仍然会将制表符插入您不需要的位置。
事实上,它的缩进很疯狂,就像它想缩进所有内容,即使它已经缩进了。
就像我说的,我已经使用它很多年了,它的随机行为仍然让我发疯。

Iv been trying to work around the eclipse indenting and other supposed features for years, and it seems that the bottom line is this ...
It only works for the programming style of the authors, so to use it you need to modify your style to comply.
This would be OK except that the authors of eclipse have some very strange ideas about common shortcut keys.
One horrid example is the search features, eg when did Ctrl+K become "Find Next occurrence" and why doesnt F3 or n work?
That all being said I use eclipse because if you have the time to wait around while it starts up - or never close it - and you can modify everything youve learned about using an editor - why why why - then it will certainly increase your efficiency.
Please note that there is a preference setting for indenting, it can be set for a project, a workspace, or globally, but no matter how you set it eclipse will still chuck tab characters in where you dont want them.
In fact its indent crazy, like it wants to indent everything, even if its already indented.
Like I said Iv been using it for years and it STILL drives me nuts with its random behavior.

差↓一点笑了 2024-08-06 09:27:11

对于 Eclipse,请执行以下步骤:

  1. 选择所有文本:ctrl+A

  2. 正确缩进:ctrl+I

Follow these steps for Eclipse:

  1. Select all text: ctrl+A

  2. Correct indentation: ctrl+I

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文