LoginSignup
8
8

More than 5 years have passed since last update.

rails.vimからrailsへの依存をなくしたprojectionist.vimを(railsで)使ってみた

Last updated at Posted at 2014-08-20

projectionist.vim とは

https://github.com/tpope/vim-projectionist
http://www.vim.org/scripts/script.php?script_id=4989

rails.vimの:Aとか:Exxxとかの機能を、railsに関係なく、jsonで記述したルールに従って使えるようになっているプラグイン。 rails.vimと共存できない。

railsで使うとどのへんが嬉しいのか

お詫びして訂正 2014/9/11

「プロジェクト固有に導入したものに対して:Aや:Exxxを使えるようにできる。」のは rails.vim でも出来ます。なので実はrailsのアプリ開発で使ってもほとんど嬉しくないです…

https://github.com/tpope/vim-rails/blob/0bb6d900af43c0fc274980ec2a8037b1f7dfdd7a/doc/rails.txt#L704 あたりに設定方法があります。

元々書いてた内容

プロジェクト固有に導入したものに対して:Aや:Exxxを使えるようにできる。例えば

  • active_decoratorを使っていれば:Edecoratorができる
  • active_adminを使っていれば、app/admin/hoge.rbから:Aでspec/features/admin/hoge_spec.rbを開ける

逆にどのへんが悲しいのか

rails.vimを使うのをやめないといけないので、:Emodelなどrails.vimでデフォルトなものの定義も書かないといけない。

何をすれば使えるのか

1. rails.vimを使わないようにする

" Bundle 'tpope/vim-rails'

2. projectionist.vimを使うようにする

Bundle 'tpope/vim-projectionist'

3. .projection.jsonを記述する

プロジェクトのルート直下に置く。

.projection.json
{
  "app/admin/*.rb": { "alternate": ["spec/features/admin/{}_spec.rb", "spec/features/admin/{plural}_spec.rb"], "type": "admin" },
  "app/controllers/*_controller.rb": { "alternate": "spec/controllers/{}_controller_spec.rb", "type": "controller" },
  "app/decorators/*_decorator.rb": { "alternate": "spec/decorators/{}_decorator_spec.rb", "type": "decorator" },
  "app/helpers/*_helper.rb": { "alternate": "spec/helpers/{}_helper_spec.rb", "type": "helper" },
  "app/mailers/*_mailer.rb": { "alternate": "spec/mailers/{}_mailer_spec.rb", "type": "mailer" },
  "app/models/*.rb": { "alternate": "spec/models/{}_spec.rb", "type": "model" },
  "app/workers/*.rb": { "alternate": "spec/workers/{}_spec.rb", "type": "worker" }
}

alternate項目を書けば:A系コマンドが、type項目を書けば:E系コマンドが使えるようになる。
:Aコマンドが一方通行なので、逆もやりたかったらそのための定義が必要っぽい。
*だけでディレクトリを再帰的に見てくれる。たとえば上記の設定でも、app/models/admin/user.rbから
:Aで
spec/models/admin/user_spec.rbを開くことができる。

詳細は :help projectionist に。

projectionという考え方自体はvim関係ないよねという話

Why not a clearer filename like .vim_projections.json?

I don't see any reason to tie the concept of projections to Vim in particular.
While some features (in particular navigation commands) are idiosyncratic to
the way Vim works, others could make sense in a wide variety of editors.

関係ないので、guard-rspecの設定も.projection.jsonを読ませるようにしてみたりしたいなーと思っている。

8
8
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
8
8