Auto-align “=” in assignments

心不动则不痛 提交于 2019-11-26 20:58:36

问题


How do one convert a block of variable assignments, e.g.:

private final String s1 = "10011";
private final String s2 = "01100";
private final String ones = "11111";
private final String zeros = "00000";

To a straightened format where all = signs are aligned to one space after the longest left-hand side, e.g.:

private final String s1    = "10011";
private final String s2    = "01100";
private final String ones  = "11111";
private final String zeros = "00000";

回答1:


PreferencesJavaCode StyleFormatter → goto Edit and check the Align fields in columns:




回答2:


If you want to be able to align assignments and not only field declarations, this plugin does an excellent job: OCDFormat.

It works in all text files, not only java.




回答3:


You can use the Eclipse plugin columns4eclipse:

  • gratis
  • open source
  • I've tested it with Eclipse 4.3 x64 and 4.5 x64 on Windows 7 SP1 x64 Ultimate




回答4:


EclipseFormatter solved this problem perfectly which supports align fields, assignments and variable declarations in columns.



来源:https://stackoverflow.com/questions/13936569/auto-align-in-assignments

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!