Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Let's say I have this code :

CommitEvent 4
FooEvent 3
BarEvent 5
NoneEvent 12

And many other lines like this. Using vim, I want to change it to :

CommitEvent => 4,
FooEvent    => 3,
BarEvent    => 5,
NoneEvent   => 12,

I tried visual block first to get the arrows but it doesn't work because the spaces are not there.

Has someone got an idea to solve this ?

share|improve this question

1 Answer 1

up vote 4 down vote accepted

Insert the arrows with a search/replace, :%s/ / => /, and then it's just a matter of aligning them. There are lots of plugins out there that help with alignment. I use Tabular. With tabular the command is :Tabularize /=>/.

share|improve this answer
2  
%s/\(.*\) \(.*\)/\1 => \2,/ to add the commas with the arrows. –  Rob May 1 '12 at 18:02
    
Or s/ \d\+/ =>&,/ –  Heptite May 1 '12 at 22:17
    
Indeed, I missed the commas. Sorry about that. –  mkomitee May 16 '12 at 20:35

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.