Search code examples
vimtabular

Vim Tabular Plugin to align two columns of text?


Worked my way through a number of Tabular pages but cannot figure this out. I want to align two columns of text. The first column is a single word, and the second column is the rest of the line:

alpha one oclock hey
beta two oclock hey
phi three oclock hey

I'd like to align it to be:

alpha one oclock hey
beta  two oclock hey
phi   three oclock hey

Also, it is possible for these lines to be already indented, so there can be spaces and tabs to the left of the first word.

I cannot figure out the regexp to make this happen. Can someone help?


Solution

  • Try this command:

    :Tabularize /^\S\+\zs/l0c1l0
    
    • ^\S\+\zs will match position after first column
    • l0c1l0 means column alignment and width.