Reputation: 157
I'm trying to use the vim plugin, Tabular, to align some misformatted CSS code. Unfortunately, I can't quite seem to grasp how to start the match at the beginning of a visual selection in Vim. Here's some example 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 at trying to left align to the start of the visual block selection hasn't yet succeeded, and I'm wondering where exactly I went wrong:
'<,'>Tabularize /\%V\s\+\zs\%V/
That is, in the visual selection, match any whitespace and then start the match. That should go up to the first word character and left align there, but I don't think Tabularize recognizes the visual block selection. Also, \%V
has no notion of ^
and breaks the regex every time. The combination ^\%V
has also failed me.
Any suggestions as to how to quickly format and align to the start of the visual block selection in vim?
Upvotes: 4
Views: 375
Reputation: 59287
You don't need Tabular to do that. Anyway, if you want to use it, do a simple:
:'<,'>Tab /^\s\+
You don't need a block selection here. By the way, it won't make much sense to work with Tabular and block selections. These are useful when things are already aligned.
But you should be able to align these lines by selecting in line-wise mode with V and then just hit =. Alternatively, use a motion like =8j and avoid the visual selection.
Upvotes: 1