LoginSignup
43
41

More than 5 years have passed since last update.

vim-rails よく使いそうなやつ

Last updated at Posted at 2014-08-12

Rails

Rails new {name}

rails new コマンド作成するだけ

:Rgenerate, :Rdestroy

rails generate / rails destroy を実行する
:Rgenerate! で最初のファイルに移動しない

:Rserver, :Rserver!

バックグラウンドでのサーバの起動 / サーバの停止

Rake

現在編集中のファイルを元に Rakeタスクを実行する

File Task
model test:units
controller test:functionals
view test:functionals
config/routes routes

ファイル操作

gf

カーソル下の文字列から適切なファイルをオープンする

例)

Post.first #=> app/models/post.rb
  ^
has_many :comments #=> app/models/comment.rb
             ^

:E*****

引数で指定した名前のファイルを編集する。
省略時は現バッファのファイル名から推測する。
(app/models/book.rb 編集中のとき :Econtoller を指定すると app/controllers/books_contoller.rbが開く)

command file
:Econtroller app/contollers/xxx_controller.rb
:Eenvironment config/application.rb
:Efixture test/fixture/xxx.yml
:Efunctionaltest test/controllers/xxxx_controller_test.rb
:Ehelper app/helpers/xxx_helper.rb
:Einitializer config/routes.rb
:Ejavascript app/assets/javascripts/books.js.coffee
:Elayout app/views/layouts/application.html.erb
:Elib Gemfile
:Elocale config/locales/en.yml
:Emailer
:Emigration db/migrate/*****_create_xxxx.rb
:Eschema db/schema.rb
:Etask spec/spec_helper.rb
:Estylesheet app/assets/stylesheets/xxxx.css.scss
:Etask Rakefile
:Eunittest test/models/test_xxx.rb または spec/models/xxx_spec.rb
:Eview app/views/xxxx/yyy.html.erb

:A,:AE,:AS,:AV,:AT,:AD

Alternate file を開く。

(:A/:AE 同じウィンドウ :AS 分割 :AV 縦分割 :AT タブ :AD 現在のバッファ)

current alternate
model unittest
controller functional test
template functional test
migration previous migration
database.yml database.example.yml

:R,:RE,:RS,:RV,:RT,:RD

Related file を開く。

(:R/:RE 同じウィンドウ :RS 分割 :RV 縦分割 :RT タブ :RD 現在のバッファ)

current related
model schema definition
controller template
template controller
migration next migration
database.yml environments/*.rb

省略入力

挿入モードで AR:: などと入力すると展開してくれる。
デフォルトでいくつか用意されている。

abbr result
AR:: ActiveRecord::
AC:: ActionContoller::
AV:: ActionView::
AM:: ActiveMailer::
AO:: Foo
bt( belongs_to(
ho( has_one(
hm( has_many(
habtm( has_and_belongs_to_many(

:Rabbr

利用可能な省略入力を表示する

:Rabbr [abbr], :Rabbr!

省略入力を定義する。長い名前空間に使うと便利

command abbr result
:Rabbr SA:: SampleApp SA:: SampleApp::

:Rabbr! は省略入力の定義を削除

misc

その他

Ctags

タグの作成
g:rails_ctags_arguments で ctags へのオプション指定

43
41
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
43
41