Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Notepad++ - Aligning text vertically in multiple columns

Tags:

notepad++

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
like image 915
Zoran Pavlovic Avatar asked Dec 09 '13 21:12

Zoran Pavlovic


People also ask

How do I align columns in notepad?

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.

How do you align text in Notepad?

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.

How do you align text vertically?

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.


1 Answers

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
like image 197
psxls Avatar answered Oct 24 '22 07:10

psxls