Today I Learned

A Hashrocket project

Create Migrations Faster with Vim-Rails

Not only can we create database migrations with vim-rails, it’s faster than using a generator. I counted the steps today and realized I was wasting precious keystrokes by underutilizing this great plugin.

Here’s how I was setting up a migration:

  • Generate the migration:
$ rails g migration add_diameter_to_wheels
  • Load the migration in Vim with :Emigration (vim-rails)
  • Replace change method with up and down methods

Here’s my improved method:

  • Generate a migration (in Vim) with :Emigration AddDiameterToWheels!
  • Create up and down methods

Less steps and characters, and best of all, we never have to leave Vim.

h/t Chris Erin

Looking for help? Hashrocket has been an industry leader in Ruby on Rails since 2008. Rails is a core skill for each developer at Hashrocket, and we'd love to take a look at your project. Contact us and find out how we can help you.