Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I indent Ruby and Rails code in Vim?

I just wonder if it´s possible to auto indent Rails Code in Vim instead of this:

validates :email, :presence => true,
  :format => { :with => email_regex },
  :uniqueness => { :case_sensitive => false }

to this:

validates :email, :presence   => true,
                  :format     => { :with => email_regex },
                  :uniqueness => { :case_sensitive => false }
like image 301
Jakob Lnr Avatar asked Apr 25 '11 19:04

Jakob Lnr


1 Answers

The best way to do this is not actually to use built-in alignment in Vim, but rather the Align Plugin by Dr. Chip, which is used to horizontally align arbitrary symbols in vertical columns.

1,3Align => will align on the =>, for example. You can get extremely detailed with the ordering etc by using the AlignCtrl function, but the extent of its functionality is likely left to its documentation. :)

like image 160
sleepynate Avatar answered Sep 22 '22 01:09

sleepynate