Is there any way to have all local variables aligned in Eclipse?
Asked Answered
H

2

6

Eclipse has a great feature to allow you to align all your 'fields in columns' meaning that it will turn:

int myVar = 2334;
int asdf = 34;
String s = "hello";

into

int     myVar  = 2334;
int     asdf   = 34;
String  s      = "Hello";

This makes the code a lot more readable and I love it. However I can't seem to find a similar setting to make it do that for regular local variables. Anyone know if there is a way? It'd be a shame if there isn't one.

Thanks

Hotspur answered 26/12, 2009 at 8:29 Comment(2)
I'd rather call that uglification, because it is misguided (I especially hate to correlate variables and their types across a lot of blank space). For local variables you should declare them where you need them, not at the beginning of a method, so this would be completely useless. Fortunately it doesn't exist AFAIK.Comptroller
Well I disagree on it making code uglier or that it's misguided. There are times that you need to declare more than 1 variable in one place and at least for me it makes it a lot easier being able to look at the variables and their types with the least effort. It may just be a preference issue thoughHotspur
P
4

If you go in Eclipse's settings, Java -> Code Style -> Formatter, you may edit or create a new profile.

Anyway, in the Indentation tab, there is an "Align fields in columns" option that should do what you are looking for.

Pythagoras answered 30/8, 2012 at 11:48 Comment(1)
fields are not local variables.Engrain
I
0

Window --> Preferences --> Java --> Code Style --> Formatter

  1. Create a New Profile
  2. check Align fields in columns
  3. click ok
  4. Select all variables declared.
  5. Ctrl + Shift + F
Iyar answered 5/7, 2019 at 3:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.