OSDN Git Service

Regular updates
[twpd/master.git] / vim-rails.md
1 ---
2 title: Vim-rails
3 category: Vim
4 html_class: key-codes
5 ---
6
7 Alternate files
8 ---------------
9
10 | `:A` |  alternate file (test)          |
11 | `:R` |  related file (controller/view) |
12
13 ### What it does
14
15 | .                     | :A                | :R              |
16 | ----                  | ---               | ---             |
17 | **Model**             | test/models/      | db/schema.rb    |
18 | **Controller method** | test/controllers/ | app/views/      |
19 | **View template**     | test/views/       | app/controllers |
20
21 Abbreviations
22 -------------
23
24 Type `:Rabbrev` for a full list.
25
26 | Abbrev  | Expansion        |
27 | ---     | ---              |
28 | `AC::`  | ActionController |
29 | `AR::`  | ActiveRecord     |
30 | `AV::`  | ActionView       |
31 | `...`   | ...              |
32 | ---     | ---              |
33 | `logd(` | logger.debug     |
34 | `logi(` | logger.info      |
35 | `...`   | ...              |
36 {:.no-head.greycode}
37
38 ### Model
39
40 | Abbrev   | Expansion                 |
41 | ---      | ---                       |
42 | `bt(`    | `belongs_to`              |
43 | `hm(`    | `has_many`                |
44 | `ho(`    | `has_one`                 |
45 | `habtm(` | `has_and_belongs_to_many` |
46 {:.no-head.greycode}
47
48 ### Controllers
49
50 | Abbrev  | Expansion        |
51 | ---     | ---              |
52 | `pa[`   | params           |
53 | `re(`   | redirect_to      |
54 | `rp(`   | render partial:  |
55 | `rst(`  | respond_to       |
56 {:.no-head.greycode}
57
58 ### Views
59
60 | Abbrev  | Expansion                   |
61 | ---     | ---                         |
62 | `dotiw` | `distance_of_time_in_words` |
63 | `taiw`  | `time_ago_in_words`         |
64 {:.no-head.greycode}
65
66 Extracting partials
67 -------------------
68
69 ```rb
70 # from view => app/views/home/_foo_partial.haml
71   :Rextract home/foo_partial
72
73 # from model => app/models/concerns/foo_concern.rb
74   :Rextract FooConcern
75 ```
76
77 Loading files
78 -------------
79
80 ### App
81
82     :Econtroller <file>     # app/controllers/*_controller.rb
83     :Ehelper                # app/helpers/*_helper.rb
84     :Emodel <file>          # app/models/*.rb
85     :Ejob <file>            # app/jobs/*_job.rb
86     :Emailer <file>         # app/mailers/*.rb
87
88 ### DB
89
90     :Emigration <file>     # db/migrations/*.rb
91     :Eschema               # db/schema.rb
92     
93 ### Lib
94
95     :Elib <file>      # lib/*.rb
96     :Elib             # Gemfile
97     :Etask <file>     # lib/tasks/*.rake
98
99 ### Assets
100
101     :Estylesheet
102     :Ejavascript
103
104 ### Views
105
106     :Eview
107     :Elayout
108
109 ### Test
110
111     :Espec
112     :Eunittest
113       # test/{unit,models,helpers}/*_test.rb
114       # spec/{unit,models,helpers}/*_spec.rb
115
116     :Efunctionaltest
117       # test/{functional,controllers,mailers}/*_test.rb
118       # spec/{functional,controllers,mailers}/*_spec.rb
119
120     :Eintegrationtest
121       # test/integration/*_test.rb
122       # spec/{features,requests,integration}/*_spec.rb
123       # features/*.feature
124
125     :Efixtures
126     :Efunctionaltest
127
128 ### Config
129
130     :Einitializer <file>          # config/initializers/*.rb
131     :Elocale                      # config/locales/*.yml
132     :Eenvironment                 # application.rb
133     :Eenvironment development     # config/environments/*.rb
134
135 ## Reference
136
137  * [vim-rails](https://github.com/tpope/vim-rails)