0

How can I use the Tabular plugin to align by ";" after "//"?

With text:

Line 1 ; B // Comment 1 ; Comment 2
Line 2 C // Comment 3    ; Comment 4

After running :Tabularize /; I get:

Line 1                ; B // Comment 1 ; Comment 2
Line 2 C // Comment 3 ; Comment 4

But how do I tabularize so that I get

Line 1  ; B // Comment 1 ; Comment 2
Line 2 C   // Comment 3  ; Comment 4
1

You could use:

:Tabularize ///[^;]*\zs;

To break it down:

  • // – match literal //.
  • [^;]* – match zero or more characters except ;.
  • \zs – set the start of the match. This is the "magic" in the regexp that makes it work; without it, the match would start at the first character (/ in this case) and Tabular would align on that, but with this it will match at the character after \zs (the desired ;).
    These sort of advanced regular expression operators can be rather hard to grok, so don't worry if you didn't quite follow that. I would encourage you to experiment. Also see :help /\zs.
  • ; – match literal ;.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.