VIM – Toggle Ruby Hash Syntax

Ruby 1.9 introduced a new json style ruby hash syntax. Although we can use this to define static hash objects and puts a limitation on the key we can use, it’s a fairly neat syntax nevertheless. However I work on several projects, both new and old and hence the new syntax is not always readily available.

To demonstrate the sheer power of regular expressions & VIM, here’s a tiny snippet that allows you to quickly toggle a ruby hash syntax from one form to other.

2 thoughts on “VIM – Toggle Ruby Hash Syntax

  1. Martin Knopf


    thanks for sharing this. But the second substitution did not work for me. It made fo:o => ‘bar’ from foo: ‘bar’. So I changed it to ‘s/\zs\s\([^: ]\w\+\):/ :\1 =>/g’. Get’s the job done.



Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.