Last Updated: February 25, 2016
·
2.636K
· apeacox

Search/Replace old Ruby hash syntax with the new 1.9+ in vim

As you may already know, Ruby 1.9, among other cool changes, introduced a new syntax to represent Hash elements. I really like that, and sometimes it's ugly to use a mix of syntaxes for the same file, or just use the old one to not waste time.

If you're a vim user, here's a simple command to replace the old syntax with the new one:

:%s/:\(\w\+\)\(\s*=>\s*\)/\1: /gc

Even if it seems to work well, I always use the c option to ask user confirmation for each matched entry. After all, it's only a matter of hitting y or n keys.

3 Responses
Add your response

Thanks, it works.

over 1 year ago ·

@samnang ehm, I know it works because I've used it for my own needs :-)

over 1 year ago ·

I put in in my vimrc:

map <leader>: :%s/:(\w+)(\s=>\s)/\1: /gc<CR>

over 1 year ago ·