Skip to content

Instantly share code, notes, and snippets.

@dtuite
Last active August 29, 2015 14:02
Show Gist options
  • Save dtuite/a89d3a1083c0b4f9a669 to your computer and use it in GitHub Desktop.
Save dtuite/a89d3a1083c0b4f9a669 to your computer and use it in GitHub Desktop.
Useful Ruby Vim Macros

.vimrc Tips and Tricks

Block Expansion

T{i<80>kbdo^M^[/}^Ms^Mend^[k

Turn a {} single line block into a do..end block.

Example:

expect { something.run }.to raise_error

Run this macro with the cursor inside the braces and it will expand to:

expect do
  something.run
end.to raise_error

Symbol Conversion

El3xi:^[bhx

Turn a rocket style symbol hash into Ruby 1.9 syntax.

Example:

my_method(:hello => 'something')

Run this macro with the cursor on the colon to get:

my_method(hello: 'something')

You can do this to all hashes in a file at once with the following mapping:

nnoremap <leader>s :%s/:\([a-z_]*\)\s=>/\1:/g<cr>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment