vimtext-editoreditingvim-plugintabular

Align rightmost column only using Vim and the Tabular plugin


I'm using Vim and the popular Tabular plugin.

I want to right-align the rightmost column of numbers only. I want to keep the other three columns exactly as they are: column 1 must remain right-aligned, and columns 2 and 3 must remain left-aligned. How do I do this?

 1  foo   bary  42
 2  foox  bar   689
 3  foo   bary  1
 4  foox  bar   3091
 5  foo   bary  2105
 6  foox  bar   7
 7  foo   bary  6
 8  foox  bar   300
 9  foo   bary  926
10  foox  bar   69
11  foo   bary  2
12  foox  bar   21

Here's the desired result.

 1  foo   bary    42
 2  foox  bar    689
 3  foo   bary     1
 4  foox  bar   3091
 5  foo   bary  2105
 6  foox  bar      7
 7  foo   bary     6
 8  foox  bar    300
 9  foo   bary   926
10  foox  bar     69
11  foo   bary     2
12  foox  bar     21

Assume for the purpose of this general class of problem that the strings that separate columns are one or more spaces.

Thank you for your help.

Jim Monty


Solution

  • This should work

    :Tabularize /[0-9]*$/l2r0
    

    Demo:

    enter image description here