クイックリファレンス

Vim-Rails プラグイン チートシート

tpope/vim-rails プラグインの早見表:関連ファイルやテストへのジャンプ(:A / :R)、パーシャルの抽出、略記補完、ファイル探索コマンド。

· 公開日

vim-rails は、Tim Pope氏によって開発されたRuby on Rails開発向けの高機能Vimプラグインです。

ファイルナビゲーション

代替ファイルおよび関連ファイルへのジャンプ

コマンド 説明
:A 代替ファイルへジャンプ (テストやspecファイル等)
:R 関連ファイルへジャンプ (コントローラ、ビュー、スキーマ等)
作業中のコンテキスト :A のジャンプ先 :R のジャンプ先
モデル (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

パーシャル (Partial) および Concern の抽出

" ERB/Hamlビューからパーシャルファイルへ抽出 => app/views/home/_foo_partial.html.erb
:Rextract home/foo_partial

" モデルから共通Concernファイルへ抽出 => app/models/concerns/foo_concern.rb
:Rextract FooConcern

Railsファイルへの直接アクセス

アプリケーションコード

: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

データベースとマイグレーション

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

ライブラリとRakeタスク

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

ビューとレイアウト

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

テストとスペック

: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

設定ファイル

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

組み込み略記スニペット (Abbreviations)

現在有効な略記一覧を確認するには、Vim内で :Rabbrev を実行します。

モデル関連の略記

略記コード 展開結果
bt( belongs_to
hm( has_many
ho( has_one
habtm( has_and_belongs_to_many

コントローラ関連の略記

略記コード 展開結果
pa[ params
re( redirect_to
rp( render partial:
rst( respond_to

公式リファレンス

関連テーマ