armando
armando

Reputation: 1480

align decimal point vim

I have a column of data which looks like this:

0.934 
-0.3423
2.346621
0.0032

I would like to have something like this:

 0.934 
-0.3423
 2.346621
 0.0032

Is there a regex in VIM to do that or a plugin?

thanks.

Upvotes: 2

Views: 373

Answers (2)

Spencer Rathbun
Spencer Rathbun

Reputation: 14910

There is the align plugin.

Upvotes: 2

kev
kev

Reputation: 161914

In linux you can do this:

:%!tr . ' ' | xargs printf '\%10s.\%-10s\n'

output:

     0.934
    -0.3423
     2.346621
     0.0032

There is a printf() function in vim. So you can play this trick in vim:

:%s/\v(.*)\.(.*)/\=printf('%10s.%-10s', submatch(1), submatch(2))

Upvotes: 2

Related Questions