Search code examples
vimpluginstabular

Aligning text on non-consecutive lines with Vim tabular plugin


I'd like to align these lines of code:

    let cty                     = -- trace ("new var " ++ (show vname) ++ " " ++ (show exp1))
              synthTy ctx vtype
        newctx                  = C.addLocalVar ctx vname cty
        ckd                     = checkExp newctx exp1 cty

like this:

    let cty     = -- trace ("new var " ++ (show vname) ++ " " ++ (show exp1))
                  synthTy ctx vtype
        newctx  = C.addLocalVar ctx vname cty
        ckd     = checkExp newctx exp1 cty

With the tabular plugin for vim, if I highlight all the lines and type :Tab /=, they align as I've typed them in the first case. I'd like them to line up like the second case. How can I get the second line to match with the second group instead of the first? I can cheat and add an equals before the words on the 2nd line, but I think there's got to be a better way.


Solution

  • Try this:

    :Tabularize/=.*$\|^\s*\zs  [^=]\+$