This page is not available in every language. Missing translations are disabled in the language selector.

Quick reference

Vim-Rails Cheatsheet

A quick reference guide for tpope/vim-rails plugin: alternate and related file navigation, file extraction, abbreviations, and Rails project jump commands.

· Published

vim-rails is a comprehensive Vim plugin for Ruby on Rails development by Tim Pope.

Navigation

Command Description
:A Jump to alternate file (e.g. test / spec)
:R Jump to related file (e.g. controller / view / schema)
Context :A Target :R Target
Model test/models/ or spec/models/ db/schema.rb
Controller test/controllers/ or spec/controllers/ app/views/<controller>/
View Template test/views/ or spec/views/ app/controllers/<controller>_controller.rb

Extracting Partials & Concerns

" From an ERB/Haml view => app/views/home/_foo_partial.html.erb
:Rextract home/foo_partial

" From a model => app/models/concerns/foo_concern.rb
:Rextract FooConcern

Opening Rails Files

Application Code

:Econtroller <name>     # app/controllers/*_controller.rb
:Ehelper <name>         # app/helpers/*_helper.rb
:Emodel <name>          # app/models/*.rb
:Ejob <name>            # app/jobs/*_job.rb
:Emailer <name>         # app/mailers/*.rb

Database & Migrations

:Emigration <name>      # db/migrate/*.rb
:Eschema                # db/schema.rb

Library & Tasks

:Elib <name>            # lib/*.rb
:Elib                   # Gemfile
:Etask <name>           # lib/tasks/*.rake

Views & Layouts

:Eview <name>           # app/views/...
:Elayout <name>         # app/views/layouts/...

Tests & Specs

:Espec <name>           # spec/.../*_spec.rb
:Eunittest <name>       # test/models/..._test.rb
:Efunctionaltest <name> # test/controllers/..._test.rb
:Eintegrationtest <name># test/integration/..._test.rb
:Efixtures <name>       # test/fixtures/*.yml

Configuration

:Einitializer <name>    # config/initializers/*.rb
:Elocale <name>         # config/locales/*.yml
:Eenvironment           # config/application.rb
:Eenvironment development # config/environments/development.rb

Built-in Abbreviations

Run :Rabbrev in Vim to inspect the complete active list.

Models

Abbreviation Expansion
bt( belongs_to
hm( has_many
ho( has_one
habtm( has_and_belongs_to_many

Controllers

Abbreviation Expansion
pa[ params
re( redirect_to
rp( render partial:
rst( respond_to

References

Related topics