cryptoKay
cryptoKay

Reputation: 111

Adding equal spaces between a word and a special charecter in VIM

I have code like:

Name,
Age,
Country,
Continent,

I want to align it like this using VIM.

Name      ,
Age       ,
Country   ,
Continent ,

How to do this?

Upvotes: 0

Views: 68

Answers (2)

SergioAraujo
SergioAraujo

Reputation: 11810

Using external command "column":

:%! column -t -s, -o, 


-s  .............. separator
-o  .............. output separator

Upvotes: 0

romainl
romainl

Reputation: 196566

Assuming your buffer only contains those lines…

  1. Substitute each trailing comma with some large number of spaces:

    :%s/,/                           /
    

    step 1

  2. Move the cursor where you want your column of commas to be:

    ell
    

    step 2

  3. Enter visual-block mode and extend the selection to the top line:

    <C-v>gg
    

    step 3

  4. Extend the selection to the end of the line:

    $
    

    step 4

  5. Change each line of the block to a comma:

    c,<Esc>
    

    step 5

Upvotes: 1

Related Questions