Environment is IntelliJ IDEA 12.
I've got Wrapping and Braces > Assignment Statement > Align when multiline
ticked. When I have adjacent properties, they're aligned correctly:
private final CustomerFactory customerFactory = FactoryBuilder.getDefaultCustomerFactory ( ); private final RepFactory repFactory = FactoryBuilder.getDefaultRepFactory ( ); private final WarehouseFactory warehouseFactory = FactoryBuilder.getDefaultWarehouseFactory ( );
but when I've got adjacent variable assignments, they're not:
final Integer account30 = parseCurrency ( fields.get ( FIELD_OVERDUE_BALANCE_1 ) ); final Integer account60 = parseCurrency ( fields.get ( FIELD_OVERDUE_BALANCE_2 ) ); final Integer account90 = parseCurrency ( fields.get ( FIELD_OVERDUE_BALANCE_3 ) ); final Integer account120 = parseCurrency ( fields.get ( FIELD_OVERDUE_BALANCE_4 ) ); final Integer priceNumber = parseInteger ( fields.get ( FIELD_PRICE_NUMBER ), 1 );
This is minor but it annoys me. Can anyone tell me what I can do to get these adjacent variable declarations aligned? What I want is:
final Integer account30 = parseCurrency ( fields.get ( FIELD_OVERDUE_BALANCE_1 ) ); final Integer account60 = parseCurrency ( fields.get ( FIELD_OVERDUE_BALANCE_2 ) ); final Integer account90 = parseCurrency ( fields.get ( FIELD_OVERDUE_BALANCE_3 ) ); final Integer account120 = parseCurrency ( fields.get ( FIELD_OVERDUE_BALANCE_4 ) ); final Integer priceNumber = parseInteger ( fields.get ( FIELD_PRICE_NUMBER ), 1 );
You can also do this using built-in key bindings without any changes to Intellij options:
How this is done:
Use the following (or equivalent) GNOME
key bindings:
=
(or any delimiter of your choosing)Add Selection for Next Occurrence
Column Selection mode
Column Selection mode
(notice selection is aligned).=
from selectionAfter backspacing to where you want the columns aligned, you should now have something like:
someVar = someVal someOtherVar = someVal someOtherOtherVar = someVal
The nice thing about this approach is it's general purpose; The above steps will align any text within whitespace so long as you choose a distinct delimiter each line contains only once, such as =
in the example given.
As noted previously, this example was performed using GNOME
key bindings. You are free to pick a different scheme in Settings
> Keymap
:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With