tags:

views:

76

answers:

1

With vim how do I to turn this:

t.string :crypted_password :null => false
t.string :password_salt, :null => false

into this:

t.string :crypted_password,  :null => false
t.string :password_salt,     :null => false

without manually adding the spaces to each line?

+4  A: 

This would be possible with the Align plugin. Conveniently enough, you actually only need to align on whitespace to accomplish this, and Align has a built-in shortcut for that: \tsp (it operates on the visual mode selection).

If actual use cases could get more complex and whitespace alignment doesn't give the result you want, you can also define your own alignment - Align lets you specify it pretty precisely, with multiple separators, skipping separators...

Another alignment plugin: Tabular (documentation here). I personally haven't used it but Greg recommends it in the comments - it delimits by regular expression instead of fixed string.

Jefromi
Nice! This is the sort of thing I was looking for. I'm gonna check it out. If it works for my case I'll mark as accepted. For now +1.
TheDeeno
I use the align plugin all the time to align text into columns or align assignments on "=". You might want to look at the Tabular plugin also, which lets you define a regex pattern for alignment. There are times the align plugin won't get there so I use tabular.
Greg
@Greg: I hadn't heard of Tabular and seem to find it on vim scripts - do you have a link?
Jefromi
@Jefromi check http://github.com/godlygeek/tabular or its docs at http://github.com/godlygeek/tabular/blob/master/doc/Tabular.txt
Greg
Perfect! Thanks again.
TheDeeno