I'm trying to align some lines in my code that has comments that could use with some alignment too. I used the notepad++ "Code-Alignment" plugin, and aligned the text below.
class Constants(object):
VAL_CONST = 5 # Lorem ipsum dolor sit amet = 213
TEST_CONST = 0.2324 # Curabitur condimentum elementum = 32
PARALLEL_CONST = 88 # Vivamus vehicula, mauris nec vehicula pulvinar, urna nibh mollis = 1342
CURVE_SPATIAL_CONST = 0.000005892 # Donec sagittis in lacus = 0.55
I end up with the following:
class Constants(object):
VAL_CONST = 5 # Lorem ipsum dolor sit amet = 213
TEST_CONST = 0.2324 # Curabitur condimentum elementum= 32
PARALLEL_CONST = 88 # Vivamus vehicula, mauris nec vehicula pulvinar, urna nibh mollis = 1342
CURVE_SPATIAL_CONST = 0.000005892 # Donec sagittis in lacus %$ 0.55
However, I'd like to take this a step further. I'd like to "re-align" the code one more time, this time on the second set of "equals" signs. Preferably without going through the comments to change the second set of equals signs to be more unique.
End result of what I'd like:
class Constants(object):
VAL_CONST = 5 # Lorem ipsum dolor sit amet = 213
TEST_CONST = 0.2324 # Curabitur condimentum elementum = 32
PARALLEL_CONST = 88 # Vivamus vehicula, mauris nec vehicula pulvinar, urna nibh mollis = 1342
CURVE_SPATIAL_CONST = 0.000005892 # Donec sagittis in lacus = 0.55
Column editing is super simple in Notepad++ 🤓 All you have to do is press the Alt key while selecting text. You can use either Alt+Mouse Dragging or Alt+Shift+Arrows. This works perfectly on text that is already aligned.
To make the text align to the right side, right-click inside the Notepad and select Right to left Reading order. To make the text align back to the left side, right-click again and uncheck the Right to left Reading order.
1 Select the text you want to center between the top and bottom margins. 2 On the Page Layout tab, click the Page Setup Dialog Box Launcher. 3 Select the Layout tab. 4 In the Vertical alignment box, click Center 5 In the Apply to box, click Selected text, and then click OK.
From Code alignment
v3 it's possible with the help of regular expressions.
First you have to align the first equal as you already did, with the ordinary way Plugins
> Code alignment
> Align by equals
.
Then, go to Plugins
> Code alignment
> Align by...
(or hit Ctrl + Shift + =) and write the following expression:
.+(?<x>=)
Don't forget to check the "Use regular expressions" option. This expression will align only the last equal, instead of the first.
These two steps will return the desired result:
class Constants(object):
VAL_CONST = 5 # Lorem ipsum dolor sit amet = 213
TEST_CONST = 0.2324 # Curabitur condimentum elementum = 32
PARALLEL_CONST = 88 # Vivamus vehicula, mauris nec vehicula pulvinar, urna nibh mollis = 1342
CURVE_SPATIAL_CONST = 0.000005892 # Donec sagittis in lacus = 0.55
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