Search code examples
vimalignment

Align text only on first separator in VIM


Suppose I have this code:

width: 215px;
height: 22px;
margin-top: 3px;
background-color: white;
border: 1px solid #999999;

I want to align it this way:

width:            215px;
height:           22px;
margin-top:       3px;
background-color: white;
border:           1px solid #999999;

using Align.vim I can do :Align \s to use whitespace as separator, but that has 2 problems

  1. the initial indent is doubled
  2. all whitespaces are considered separators, so the last line is messed up

I've read through the many options Align.vim offers, but I haven't found a way to do this.


Solution

  • If you use Tabular, then you can just do :Tabularize /:\zs/.

    Looking at Align's description on vim.org, a similar invocation should work for it. You could try :Align :\zs. I don't use Align, so I'm not positive.