qpnqdg
Last Updated: February 25, 2016
·
1.857K
· apeacox
Eda3d93f49a394d603bd5ecd7c821269

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

5891
863e24c91fcf1cd3c879ea62a401365e

Thanks, it works.

over 1 year ago ·
5907
Eda3d93f49a394d603bd5ecd7c821269

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

over 1 year ago ·
5908
863e24c91fcf1cd3c879ea62a401365e

I put in in my vimrc:

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

over 1 year ago ·