Notepad++ - Aligning text vertically in multiple c

2019-02-21 21:29发布

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

标签: notepad++
2条回答
虎瘦雄心在
2楼-- · 2019-02-21 22:00

I have been using Code Alignment plugin for a while and found it to be very useful. But it has two major issues from my point of view:

  • it aligns only the first column given the delimiter character
  • it uses .NET framework which makes it very slow at start-up and adds an extra dependency

I decided to create an alternative:

https://github.com/duzun/nppPyAlignColumn

This is a Python Script for Notepad++ Plugin named Python Script, that can be run from Menu. It takes as input any string to be used as delimiter of columns and aligns all the columns in the selected lines.

查看更多
Evening l夕情丶
3楼-- · 2019-02-21 22:06

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
查看更多
登录 后发表回答