Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
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
%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


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.