Aligning text
Aligning text

Reputation: 1

How to align text?

Is is possible to format the following text so the text after : is in specific column (like 70)?

body:
X  width:                                    100%
// This is comment
   min->
X    width:  960px
   a:
     &:hoover:
X      family:                       $main_fonts
   background->
X    image:                                  url('img/image.png')
X    position:     top center
X    repeat:         repeat
X  color: #000

but just for lines which contain X (X at the front is just for showing which line to format, it's not in the real file). I tried to use Align by Charles Campbell but no luck :(

The resulting text should be like:

body:
  width:                                             100%
// This is comment
   min->
    width:                                           960px
   a:
     &:hoover:
      family:                                        $main_fonts
   background->
    image:                                           url('img/image.png')
    position:                                        top center
    repeat:                                          repeat
  color:                                             #000

Upvotes: 0

Views: 1036

Answers (2)

Alan Gómez
Alan Gómez

Reputation: 378

Use the following regex:

%s/:\s\+/: /g

OR

:%s/^.*:\zs/ /g to assure match the final : character

Then: :%s/\%>25c\s\{2,}//g

Best regards!

Upvotes: 0

dahu
dahu

Reputation: 329

In vim with the Tabular plugin, use V to linewise visually select the area you want to format and then :'<,'>Tabular /:\s+\zs/l0l70 (and spiiph was right :)

Upvotes: 1

Related Questions