I read through :help rails.txt to see if Rails.vim included anything useful that I wasn’t using already.
The biggest discovery was how customizable it is.
Customize alternate file mappings
Rails.vim lets you jump between “alternate files” with :A. Typically, that’s something like app/models/item.rb ↔ spec/models/item_spec.rb.
If you stray too far from the Rails conventions, though, :A can no longer help you.
We have a Rails-less test suite in unit and engines right inside the main app for technical reasons. When we’re working on any of those files, :A does not work and we grumble. Clearly we were not intended to test things outside Rails.
But it turns out it’s fairly easy to add your own mappings, even with fallbacks. This is now in our Vim configs:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | |
Note that in the third example, it looks for an alternate in spec, with unit as a fallback.
Though I haven’t seen a use for it yet, you could change the :R “related file” mappings in much the same way. Maybe to jump between your two god classes?
Customize navigation commands
Rails.vim comes with commands like :Rmodel and :Rcontroller to open a certain type of file with autocompletion.
Turns out you can add your own navigation commands. I added two, for Fabrication (which we’re moving away from) and FactoryGirl factories:
1 2 3 4 5 | |
With that, you simply run :Rfac item<Enter> or :Rfac it<Tab><Enter> to open spec/factories/item_factory.rb.