Vim: start regex from the beginning of Visual selection

I am trying to use the vim plugin, Tabular , to align some invalid CSS code. Unfortunately, I can’t understand how to start a match at the beginning of the visual selection in Vim. Here is a sample code:

color: #a8a8a8;font-family: Helvetica; color: #d0d0d0; font-weight: normal; background-color: inherit; font-size: 13px !important; background-color: inherit; width: 16px; min-width: 16px; display: inline-block; margin-right: 2ex; margin-left: 2px; text-align: center; height: 0; line-height: .5ex; padding-top: 1ex; background: transparent; 

My attempt to try left-justifying the beginning of the selection of the visual block has failed, and I wonder where exactly I made a mistake:

 '<,'>Tabularize /\%V\s\+\zs\%V/ 

That is, in the visual selection, match any gaps and then start the match. This should go as far as the first word character and left alignment, but I don't think Tabularize recognizes the choice of the visual block. In addition, \%V has no clue ^ and breaks the regular expression each time. The combination ^\%V also failed me.

Any suggestions on how to quickly format and align the start of selecting a visual block in vim?

+4
source share
1 answer

You do not need Tabular for this. Anyway, if you want to use it, make it simple:

 :'<,'>Tab /^\s\+ 

Here you do not need a block selection. By the way, it makes no sense to work with table and block selections. They are useful when things are already aligned.

But you should be able to align these lines by selecting in linear mode with V , and then just press = . As an alternative, use a motion of type = 8 j and avoid visual selection.

+1
source

All Articles