Eclipse 编辑器是否具有等效于 Emacs 的“align-regex"? [英] Does the Eclipse editor have an equivalent of Emacs's "align-regex"?

查看:25
本文介绍了Eclipse 编辑器是否具有等效于 Emacs 的“align-regex"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

几年来我一直经常使用 Eclipse,但我承认我没有探索过它所提供的所有奥秘,特别是在编辑器提供的格式化功能方面.

I've been using Eclipse pretty regularly for several years now, but I admit to not having explored all the esoterica it has to offer, particularly in the areas of what formatting features the editors offer.

我从 (X)emacs 中错过的主要内容是align-regex"命令,它让我将多行放入一个区域,然后将它们格式化,以便对齐所有行中的一些常见模式.最简单的例子是一系列变量赋值:

The main thing I miss from (X)emacs is the "align-regex" command, which let me take several lines into a region and then format them so that some common pattern in all lines was aligned. The simplest example of this is a series of variable assignments:

var str = new String('aString');
var index = 0;
var longCamelCaseObjectName = new LongNameObject();

在="上做align-regex后,会变成:

After doing align-regex on "=", that would become:

var str                     = new String('aString');
var index                   = 0;
var longCamelCaseObjectName = new LongNameObject();

现在,您可能对空白和对齐等的风格(ab)使用有自己的想法,但这只是一个例子(我实际上是在尝试完全对齐另一种混乱).

Now, you may have your own thoughts on stylistic (ab)use of white space and alignment, etc., but that's just an example (I'm actually trying to align a different kind of mess entirely).

谁能直接告诉我在 Eclipse 中是否有一个简单的组合快捷键?或者甚至是一个中等难度的?

Can anyone tell me off-hand if there's an easy key-combo-shortcut for this in Eclipse? Or even a moderately-tricky one?

推荐答案

您可以设置格式化程序来执行此操作:

You can set the formatter to do this:

首选项 -> Java -> 代码样式 -> 格式化程序.点击配置文件上的编辑"(您可能需要创建一个新的,因为您无法编辑默认设置).

Preferences -> Java -> Code Style -> Formatter. Click 'Edit' on the profile (you may need to make a new one since you can't edit the default).

在缩进部分选择将字段与列对齐".

In the indentation section select 'Align fields with columns'.

然后,在您的代码中 CTRL+SHIFT+F 将运行该格式化程序.

Then, in your code CTRL+SHIFT+F will run that formatter.

这当然会运行所有其他规则,因此您可能需要仔细阅读此处的各种选项.

That will of course run all the other rules, so you may want to peruse the various options here.

这篇关于Eclipse 编辑器是否具有等效于 Emacs 的“align-regex"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆