Today I Learned

hashrocket A Hashrocket project

Tabularize in VIM - changing whitespaces count

In order to tabularize texts based on comma character use the tabular vim plugin:

:Tabularize /,

This will by default add at least 1 whitespace to the left and exactly 1 whitespace to the right.

You can change this adding /l<NUM>r<NUM> to the end of command.

For 0 to the left and 1 to the right:

:Tabularize /,/l0r1

example:

# original
resources :posts, path: 'blog_posts', only: [:index, :show, :create]
resources :comments, path: 'user_comments', only: [:index, :show]

# :Tabularize /,
resources :posts    , path: 'blog_posts'    , only: [:index , :show  , :create]
resources :comments , path: 'user_comments' , only: [:index , :show]

# :Tabularize /,/l0r1
resources :posts   , path: 'blog_posts'   , only: [:index, :show , :create]
resources :comments, path: 'user_comments', only: [:index, :show]

reference

See More #vim TILs
Every developer at Hashrocket is a Vim expert. Check out our development environment, Dotmatrix, and if you are in Chicago, come to the Vim Chicago Meetup hosted at our Chicago office.