Last Updated: February 25, 2016
·
1.697K
· croaky

Vim Mappings for a Ruby Style Guide

Convert Ruby 1.8 to 1.9 hash syntax:

nnoremap <Leader>: :%s/:\([^ ]*\)\(\s*\)=>/\1:/gc<CR>

Add whitespace inside of braces {}:

nnoremap <Leader>{ :%s/{\([^ ]\)/{ \1/gc<CR>
nnoremap <Leader>} :%s/\([^ ]\)}/\1 }/gc<CR>

As these are not commonly used, it may be more appropriate to add them into a
separate file such as ~/.vimrc.refactoring. Then, source that file when
needed in the current Vim session:

source ~/.vimrc.refactoring

Bonus: how to convert to Ruby 1.9 hash syntax for a whole project.