Vim Aligning Inline Comments

Not really sure how to express this any other way than with an example.

Considering,...

DATABASES = {
'default': {
    'ENGINE': 'django.db.backends.mysql',    # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
    'NAME': 'adroit',                      # Or path to database file if using sqlite3.
    'USER': 'root',                    # Not used with sqlite3.
    'PASSWORD': '',                      # Not used with sqlite3.
    'HOST': '',                         # Set to empty string for localhost. Not used with sqlite3.
    'PORT': '',                            # Set to empty string for default. Not used with sqlite3.
}

      

}

How do I format it so that all comments match correctly, like

DATABASES = {
'default': {
    'ENGINE': 'django.db.backends.mysql',  # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
    'NAME': 'adroit',                      # Or path to database file if using sqlite3.
    'USER': 'root',                        # Not used with sqlite3.
    'PASSWORD': '',                        # Not used with sqlite3.
    'HOST': '',                            # Set to empty string for localhost. Not used with sqlite3.
    'PORT': '',                            # Set to empty string for default. Not used with sqlite3.
}

      

}

The above example is from a django settings file, but I often encounter this problem in different languages, so ideally I would look for a way to do this regardless of the comment delimiter.

+3


source to share


1 answer


Use tabular . With this plugin, you can simply visually select the part you want to align and then enter:

'<,'>Tabularize /#

      



It works so beautifully that it looks like magic.

+5


source







All Articles