How to insert variable number of spaces necessary to align textual columns in Vim?

I'm much better off without any vim plugins. Here is my solution:

<Shift-V>jj:!column -ts --

Then insert -- into multiple lines just as you wrote in the question.


You can also append a number of comments at insertion time.

:set virtualedit=all

<Ctrl-V>jjA-- xxx<Esc>


You have to use a specific plugin, you can use either Tabular or Align plugin in this case.

They both allow you to align text on specific characters, like -- in your example. Their syntax is a bit different though. Pick the one that suit you the most.


Without plugin and if you have already entered your comments without emix's solution:

:,+2 s/--/                                    &

This will ensure all comments are to be shifted leftwise in order to align them properly.

Then blockwise select the column to which you want to align the text, and : 100<