tomkersten-vixploder 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +4 -0
- data/Manifest.txt +105 -0
- data/PostInstall.txt +21 -0
- data/README.rdoc +131 -0
- data/Rakefile +21 -0
- data/bin/256colors2.pl +63 -0
- data/bin/colortest +365 -0
- data/bin/vixplode +10 -0
- data/lib/dotfiles/aliases +30 -0
- data/lib/dotfiles/gvimrc +20 -0
- data/lib/dotfiles/vim/.VimballRecord +2 -0
- data/lib/dotfiles/vim/after/ftplugin/actionscript_snippets.vim +9 -0
- data/lib/dotfiles/vim/after/ftplugin/aspvbs_snippets.vim +17 -0
- data/lib/dotfiles/vim/after/ftplugin/c_snippets.vim +58 -0
- data/lib/dotfiles/vim/after/ftplugin/css_snippets.vim +30 -0
- data/lib/dotfiles/vim/after/ftplugin/django_model_snippets.vim +61 -0
- data/lib/dotfiles/vim/after/ftplugin/django_template_snippets.vim +32 -0
- data/lib/dotfiles/vim/after/ftplugin/f-script_snippets.vim +14 -0
- data/lib/dotfiles/vim/after/ftplugin/haskell_snippets.vim +9 -0
- data/lib/dotfiles/vim/after/ftplugin/html_snippets.vim +57 -0
- data/lib/dotfiles/vim/after/ftplugin/java_snippets.vim +52 -0
- data/lib/dotfiles/vim/after/ftplugin/javascript_snippets.vim +10 -0
- data/lib/dotfiles/vim/after/ftplugin/latex_snippets.vim +13 -0
- data/lib/dotfiles/vim/after/ftplugin/logo_snippets.vim +9 -0
- data/lib/dotfiles/vim/after/ftplugin/markdown_snippets.vim +10 -0
- data/lib/dotfiles/vim/after/ftplugin/movable_type_snippets.vim +14 -0
- data/lib/dotfiles/vim/after/ftplugin/objc_snippets.vim +53 -0
- data/lib/dotfiles/vim/after/ftplugin/ocaml_snippets.vim +26 -0
- data/lib/dotfiles/vim/after/ftplugin/perl_snippets.vim +23 -0
- data/lib/dotfiles/vim/after/ftplugin/php_snippets.vim +30 -0
- data/lib/dotfiles/vim/after/ftplugin/phpdoc_snippets.vim +19 -0
- data/lib/dotfiles/vim/after/ftplugin/propel_snippets.vim +14 -0
- data/lib/dotfiles/vim/after/ftplugin/python_snippets.vim +202 -0
- data/lib/dotfiles/vim/after/ftplugin/rails_snippets.vim +54 -0
- data/lib/dotfiles/vim/after/ftplugin/ruby_snippets.vim +32 -0
- data/lib/dotfiles/vim/after/ftplugin/sh_snippets.vim +12 -0
- data/lib/dotfiles/vim/after/ftplugin/slate_snippets.vim +19 -0
- data/lib/dotfiles/vim/after/ftplugin/smarty_snippets.vim +35 -0
- data/lib/dotfiles/vim/after/ftplugin/symfony_snippets.vim +21 -0
- data/lib/dotfiles/vim/after/ftplugin/tcl_snippets.vim +14 -0
- data/lib/dotfiles/vim/after/ftplugin/template_toolkit_snippets.vim +13 -0
- data/lib/dotfiles/vim/after/ftplugin/tex_snippets.vim +13 -0
- data/lib/dotfiles/vim/after/ftplugin/xhtml_snippets.vim +48 -0
- data/lib/dotfiles/vim/autoload/fakeclip.vim +253 -0
- data/lib/dotfiles/vim/autoload/rails.vim +4377 -0
- data/lib/dotfiles/vim/autoload/rubycomplete.vim +802 -0
- data/lib/dotfiles/vim/colors/inkpot.vim +212 -0
- data/lib/dotfiles/vim/colors/ir_black.vim +212 -0
- data/lib/dotfiles/vim/colors/ir_black_mod.vim +213 -0
- data/lib/dotfiles/vim/colors/railscasts.vim +100 -0
- data/lib/dotfiles/vim/colors/rubyblue.vim +74 -0
- data/lib/dotfiles/vim/colors/twilight.vim +75 -0
- data/lib/dotfiles/vim/colors/twilight2.vim +74 -0
- data/lib/dotfiles/vim/colors/wombat256.vim +302 -0
- data/lib/dotfiles/vim/compiler/eruby.vim +41 -0
- data/lib/dotfiles/vim/compiler/ruby.vim +68 -0
- data/lib/dotfiles/vim/compiler/rubyunit.vim +35 -0
- data/lib/dotfiles/vim/doc/NERD_tree.txt +1235 -0
- data/lib/dotfiles/vim/doc/fakeclip.txt +190 -0
- data/lib/dotfiles/vim/doc/matchit.txt +406 -0
- data/lib/dotfiles/vim/doc/project.txt +710 -0
- data/lib/dotfiles/vim/doc/rails.txt +1123 -0
- data/lib/dotfiles/vim/doc/snippets_emu.txt +354 -0
- data/lib/dotfiles/vim/doc/surround.txt +218 -0
- data/lib/dotfiles/vim/doc/tags +433 -0
- data/lib/dotfiles/vim/filetype.vim +13 -0
- data/lib/dotfiles/vim/ftdetect/gist.vim +3 -0
- data/lib/dotfiles/vim/ftdetect/ruby.vim +14 -0
- data/lib/dotfiles/vim/ftplugin/eruby.vim +101 -0
- data/lib/dotfiles/vim/ftplugin/ruby.vim +230 -0
- data/lib/dotfiles/vim/indent/eruby.vim +73 -0
- data/lib/dotfiles/vim/indent/ruby.vim +373 -0
- data/lib/dotfiles/vim/plugin/NERD_tree.vim +3536 -0
- data/lib/dotfiles/vim/plugin/comments.vim +321 -0
- data/lib/dotfiles/vim/plugin/fakeclip.vim +174 -0
- data/lib/dotfiles/vim/plugin/fuzzyfinder.vim +1676 -0
- data/lib/dotfiles/vim/plugin/fuzzyfinder_textmate.vim +150 -0
- data/lib/dotfiles/vim/plugin/gist.vim +241 -0
- data/lib/dotfiles/vim/plugin/gitdiff.vim +141 -0
- data/lib/dotfiles/vim/plugin/matchit.vim +812 -0
- data/lib/dotfiles/vim/plugin/mru.vim +787 -0
- data/lib/dotfiles/vim/plugin/rails.vim +310 -0
- data/lib/dotfiles/vim/plugin/rspec.vim +12 -0
- data/lib/dotfiles/vim/plugin/snippets.vim +17 -0
- data/lib/dotfiles/vim/plugin/snippetsEmu.vim +973 -0
- data/lib/dotfiles/vim/plugin/supertab.vim +531 -0
- data/lib/dotfiles/vim/plugin/surround.vim +632 -0
- data/lib/dotfiles/vim/ref_vimrc +80 -0
- data/lib/dotfiles/vim/ruby/fuzzy_file_finder.rb +353 -0
- data/lib/dotfiles/vim/syntax/eruby.vim +85 -0
- data/lib/dotfiles/vim/syntax/haml.vim +113 -0
- data/lib/dotfiles/vim/syntax/mkd.vim +86 -0
- data/lib/dotfiles/vim/syntax/ruby.vim +324 -0
- data/lib/dotfiles/vim/syntax/sass.vim +93 -0
- data/lib/dotfiles/vimrc +269 -0
- data/lib/vixplode/cli.rb +73 -0
- data/lib/vixploder.rb +6 -0
- data/script/console +10 -0
- data/script/destroy +14 -0
- data/script/generate +14 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +10 -0
- data/spec/vixplode_cli_spec.rb +15 -0
- data/spec/vixploder_spec.rb +7 -0
- data/tasks/rspec.rake +21 -0
- metadata +202 -8
@@ -0,0 +1,1123 @@
|
|
1
|
+
*rails.txt* Plugin for working with Ruby on Rails applications
|
2
|
+
|
3
|
+
Author: Tim Pope <vimNOSPAM@tpope.info> |rails-plugin-author|
|
4
|
+
|
5
|
+
|rails-introduction| Introduction and Feature Summary
|
6
|
+
|rails-installation| Installation and Usage
|
7
|
+
|rails-install-vim| Installing and Configuring Vim
|
8
|
+
|rails-install-plugin| Installing and Using the Plugin
|
9
|
+
|rails-commands| General Commands
|
10
|
+
|rails-navigation| Navigation
|
11
|
+
|rails-gf| File Under Cursor - gf
|
12
|
+
|rails-alternate-related| Alternate and Related Files
|
13
|
+
|rails-model-navigation| Model Navigation Commands
|
14
|
+
|rails-controller-navigation| Controller Navigation Commands
|
15
|
+
|rails-misc-navigation| Miscellaneous Navigation Commands
|
16
|
+
|rails-custom-navigation| Custom Navigation Commands
|
17
|
+
|rails-scripts| Script Wrappers
|
18
|
+
|rails-refactoring| Refactoring Helpers
|
19
|
+
|rails-partials| Partial Extraction
|
20
|
+
|rails-migrations| Migration Inversion
|
21
|
+
|rails-integration| Integration
|
22
|
+
|rails-vim-integration| Integration with the Vim Universe
|
23
|
+
|rails-rails-integration| Integration with the Rails Universe
|
24
|
+
|rails-abbreviations| Abbreviations
|
25
|
+
|rails-syntax| Syntax Highlighting
|
26
|
+
|rails-options| Managed Vim Options
|
27
|
+
|rails-configuration| Configuration
|
28
|
+
|rails-global-settings| Global Settings
|
29
|
+
|rails-about| About rails.vim
|
30
|
+
|rails-license| License
|
31
|
+
|
32
|
+
This plugin is only available if 'compatible' is not set.
|
33
|
+
|
34
|
+
{Vi does not have any of this}
|
35
|
+
|
36
|
+
==============================================================================
|
37
|
+
INTRODUCTION *rails-introduction* *rails*
|
38
|
+
|
39
|
+
TextMate may be the latest craze for developing Ruby on Rails applications,
|
40
|
+
but Vim is forever. This plugin offers the following features for Ruby on
|
41
|
+
Rails application development.
|
42
|
+
|
43
|
+
1. Automatically detects buffers containing files from Rails applications,
|
44
|
+
and applies settings to those buffers (and only those buffers). You can
|
45
|
+
use an autocommand to apply your own custom settings as well.
|
46
|
+
|rails-configuration|
|
47
|
+
|
48
|
+
2. Unintrusive. Only files in a Rails application should be affected; regular
|
49
|
+
Ruby scripts are left untouched. Even when enabled, the plugin should keep
|
50
|
+
out of your way if you're not using its features. (If you find a situation
|
51
|
+
where this is not a case, contact the |rails-plugin-author|.)
|
52
|
+
|
53
|
+
3. Provides reasonable settings for working with Rails applications. Rake is
|
54
|
+
the 'makeprg' (and it always knows where your Rakefile is), 'shiftwidth'
|
55
|
+
is 2, and 'path' includes an appropriate collection of directories from
|
56
|
+
your application. |rails-options|
|
57
|
+
|
58
|
+
4. Easy navigation of the Rails directory structure. |gf| considers context
|
59
|
+
and knows about partials, fixtures, and much more. There are two commands,
|
60
|
+
:A (alternate) and :R (related) for easy jumping between files, including
|
61
|
+
favorites like model to migration, template to helper, and controller to
|
62
|
+
functional test. For more advanced usage, :Rmodel, :Rview, :Rcontroller,
|
63
|
+
and several other commands are provided. |rails-navigation|
|
64
|
+
|
65
|
+
5. Enhanced syntax highlighting. From has_and_belongs_to_many to
|
66
|
+
distance_of_time_in_words, it's here. For Vim 7 users, 'completefunc' is
|
67
|
+
set to enable syntax based completion on |i_CTRL-X_CTRL-U|, making it easy
|
68
|
+
to complete such long method names. |rails-syntax|
|
69
|
+
|
70
|
+
6. Interface to script/*. Generally, use ":Rscript about" to call
|
71
|
+
"script/about". Most commands have wrappers with additional features:
|
72
|
+
":Rgenerate controller Blog" generates a blog controller and edits
|
73
|
+
app/controllers/blog_controller.rb. |rails-scripts|
|
74
|
+
|
75
|
+
7. Partial extraction and migration inversion. |:Rextract| {file} replaces
|
76
|
+
the desired range (ideally selected in visual line mode) with "render
|
77
|
+
:partial => '{file}'", which is automatically created with your content.
|
78
|
+
The @{file} instance variable is replaced with the {file} local variable.
|
79
|
+
|:Rinvert| takes a self.up migration and writes a self.down.
|
80
|
+
|rails-refactoring|
|
81
|
+
|
82
|
+
8. Integration with other plugins. |:Rproject| creates a new project.vim
|
83
|
+
project. |:Rdbext| loads database settings from database.yml for dbext.vim
|
84
|
+
(and this happens by default under most circumstances). Cream users get
|
85
|
+
some additional mappings, and all GUI users get a menu. |rails-integration|
|
86
|
+
|
87
|
+
==============================================================================
|
88
|
+
INSTALLATION AND USAGE *rails-installation*
|
89
|
+
|
90
|
+
If you are familiar Vim and have the latest version installed, you may skip
|
91
|
+
directly to |rails-install-plugin| below.
|
92
|
+
|
93
|
+
Installing and Configuring Vim ~
|
94
|
+
*rails-install-vim*
|
95
|
+
Because it is common for users to utilize an older version of Vim that came
|
96
|
+
installed on a system, rails.vim has a design goal of remaining compatible
|
97
|
+
with versions of Vim 6.2 and newer. However, if you have a choice in the
|
98
|
+
matter, you are strongly encouraged to install the latest version available.
|
99
|
+
Older versions of Vim should work, but increasingly, new plugin features will
|
100
|
+
require Vim 7 or newer. If possible, install a version of Vim with the |Ruby|
|
101
|
+
interface compiled in, as a few features will make use of it when available.
|
102
|
+
|
103
|
+
If you are new to Vim, you need to create a vimrc. For Windows, this file
|
104
|
+
goes in ~\_vimrc (try :e ~\_vimrc if you don't know where this is). On other
|
105
|
+
platforms, use ~/.vimrc. A very minimal example file is shown below.
|
106
|
+
>
|
107
|
+
set nocompatible
|
108
|
+
syntax on
|
109
|
+
filetype plugin indent on
|
110
|
+
>
|
111
|
+
Installing and Using the Plugin ~
|
112
|
+
*rails-install-plugin*
|
113
|
+
If you have the zip file, extract it to vimfiles (Windows) or ~/.vim
|
114
|
+
(everything else). You should have the following files: >
|
115
|
+
autoload/rails.vim
|
116
|
+
plugin/rails.vim
|
117
|
+
doc/rails.txt
|
118
|
+
See |add-local-help| for instructions on enabling the documentation. In a
|
119
|
+
nutshell: >
|
120
|
+
:helptags ~/.vim/doc
|
121
|
+
|
122
|
+
Whenever you edit a file in a Rails application, this plugin will be
|
123
|
+
automatically activated. This sets various options and defines a few
|
124
|
+
buffer-specific commands.
|
125
|
+
|
126
|
+
If you are in a hurry to get started, with a minimal amount of reading, you
|
127
|
+
are encouraged to at least skim through the headings and command names in this
|
128
|
+
file, to get a better idea of what is offered. If you only read one thing,
|
129
|
+
make sure it is the navigation section: |rails-navigation|.
|
130
|
+
|
131
|
+
==============================================================================
|
132
|
+
GENERAL COMMANDS *rails-commands*
|
133
|
+
|
134
|
+
All commands are buffer local, unless otherwise stated. This means you must
|
135
|
+
actually edit a file from a Rails application.
|
136
|
+
|
137
|
+
*rails-:Rails*
|
138
|
+
:Rails {directory} The only global command. Creates a new Rails
|
139
|
+
application in {directory}, and loads the README.
|
140
|
+
|
141
|
+
*rails-:Rake*
|
142
|
+
:Rake {targets} Like calling |:make| {targets} (with 'makeprg' being
|
143
|
+
rake). However, in some contexts, if {targets} are
|
144
|
+
omitted, :Rake defaults to something sensible (like
|
145
|
+
db:migrate in a migration, or your current test).
|
146
|
+
|
147
|
+
*rails-:Rake!*
|
148
|
+
:Rake! {targets} Called with a bang, :Rake will use an alternate
|
149
|
+
'errorformat' which attempts to parse the full stack
|
150
|
+
backtrace.
|
151
|
+
|
152
|
+
*rails-:Rcd*
|
153
|
+
:Rcd [{directory}] |:cd| to /path/to/railsapp/{directory}.
|
154
|
+
|
155
|
+
*rails-:Rlcd*
|
156
|
+
:Rlcd [{directory}] |:lcd| to /path/to/railsapp/{directory}.
|
157
|
+
|
158
|
+
*rails-:Rdoc*
|
159
|
+
:Rdoc Browse to the Rails API, either in doc/api in the
|
160
|
+
current Rails application, gem_server if it is
|
161
|
+
running, or http://api.rubyonrails.org/ . Requires
|
162
|
+
:OpenURL to be defined (see |rails-:OpenURL|).
|
163
|
+
|
164
|
+
*rails-:Rdoc!*
|
165
|
+
:Rdoc! Make the appropriate |:helptags| call and invoke
|
166
|
+
|:help| rails.
|
167
|
+
|
168
|
+
*rails-:Redit*
|
169
|
+
:Redit {file} Edit {file}, relative to the application root.
|
170
|
+
|
171
|
+
*rails-:Rlog*
|
172
|
+
:Rlog [{logfile}] Split window and open {logfile} ($RAILS_ENV or
|
173
|
+
development by default). The control characters used
|
174
|
+
for highlighting are removed. If you have a :Tail
|
175
|
+
command (provided by |tailminusf|.vim), that is used;
|
176
|
+
otherwise, the file does NOT reload upon change.
|
177
|
+
Use |:checktime| to tell Vim to check for changes.
|
178
|
+
|G| has been mapped to do just that prior to jumping
|
179
|
+
to the end of the file, and q is mapped to close the
|
180
|
+
window. If the delay in loading is too long, you
|
181
|
+
might like :Rake log:clear.
|
182
|
+
|
183
|
+
*rails-:Rpreview*
|
184
|
+
:Rpreview [{path}] Creates a URL from http://localhost:3000/ and the
|
185
|
+
{path} given. If {path} is omitted, a sensible
|
186
|
+
default is used (considers the current
|
187
|
+
controller/template, but does not take routing into
|
188
|
+
account). The not too useful default is to then edit
|
189
|
+
this URL using Vim itself, allowing |netrw| to
|
190
|
+
download it. More useful is to define a :OpenURL
|
191
|
+
command, which will be used instead (see
|
192
|
+
|rails-:OpenURL|).
|
193
|
+
|
194
|
+
*rails-:Rpreview!*
|
195
|
+
:Rpreview! [{path}] As with :Rpreview, except :OpenURL is never used.
|
196
|
+
|
197
|
+
*rails-:Rtags*
|
198
|
+
:Rtags Calls ctags -R on the current application root.
|
199
|
+
Exuberant ctags must be installed.
|
200
|
+
|
201
|
+
*rails-:Rrefresh*
|
202
|
+
:Rrefresh Refreshes certain cached settings. Most noticeably,
|
203
|
+
this clears the cached list of classes that are syntax
|
204
|
+
highlighted as railsUserClass.
|
205
|
+
|
206
|
+
*rails-:Rrefresh!*
|
207
|
+
:Rrefresh! As above, and also reloads rails.vim.
|
208
|
+
|
209
|
+
*rails-:OpenURL*
|
210
|
+
:OpenURL {url} This is not a command provided by the plugin, but
|
211
|
+
rather provided by user and utilized by other plugin
|
212
|
+
features. This command should be defined to open the
|
213
|
+
provided {url} in a web browser. An example command
|
214
|
+
on a Mac might be: >
|
215
|
+
:command -bar -nargs=1 OpenURL :!open <args>
|
216
|
+
< The following appears to work on Windows: >
|
217
|
+
:command -bar -nargs=1 OpenURL :!start cmd /cstart /b <args>
|
218
|
+
< On Debian compatible distributions, the following is
|
219
|
+
the preferred method: >
|
220
|
+
:command -bar -nargs=1 OpenURL :!sensible-browser <args>
|
221
|
+
< If exists("$SECURITYSESSIONID"), has("gui_win32"), or
|
222
|
+
executable("sensible-browser") is true, the
|
223
|
+
corresponding command above will be automatically
|
224
|
+
defined. Otherwise, you must provide your own (which
|
225
|
+
is recommended, regardless).
|
226
|
+
|
227
|
+
==============================================================================
|
228
|
+
NAVIGATION *rails-navigation*
|
229
|
+
|
230
|
+
Navigation is where the real power of this plugin lies. Efficient use of the
|
231
|
+
following features will greatly ease navigating the Rails file structure.
|
232
|
+
|
233
|
+
The 'path' has been modified to include all the best places to be.
|
234
|
+
>
|
235
|
+
:find blog_controller
|
236
|
+
:find book_test
|
237
|
+
<
|
238
|
+
*rails-:Rfind*
|
239
|
+
:Rfind [{file}] Find {file}. Very similar to :find, but things like
|
240
|
+
BlogController are properly handled, and if
|
241
|
+
genutils.vim is installed (1.x not 2.x), tab complete
|
242
|
+
works. The default filename is taken from under the
|
243
|
+
cursor in a manner quite similar to gf, described
|
244
|
+
below.
|
245
|
+
|
246
|
+
File Under Cursor - gf ~
|
247
|
+
*rails-gf*
|
248
|
+
The |gf| command, which normally edits the current file under the cursor, has
|
249
|
+
been remapped to take context into account. |CTRL-W_f|(open in new window) and
|
250
|
+
|CTRL-W_gf| (open in new tab) are also remapped.
|
251
|
+
|
252
|
+
Example uses of |gf|, and where they might lead.
|
253
|
+
(* indicates cursor position)
|
254
|
+
>
|
255
|
+
Pos*t.find(:first)
|
256
|
+
< app/models/post.rb ~
|
257
|
+
>
|
258
|
+
has_many :c*omments
|
259
|
+
< app/models/comment.rb ~
|
260
|
+
>
|
261
|
+
link_to "Home", :controller => :bl*og
|
262
|
+
< app/controllers/blog_controller.rb ~
|
263
|
+
>
|
264
|
+
<%= render :partial => 'sh*ared/sidebar' %>
|
265
|
+
< app/views/shared/_sidebar.rhtml ~
|
266
|
+
>
|
267
|
+
<%= stylesheet_link_tag :scaf*fold %>
|
268
|
+
< public/stylesheets/scaffold.css ~
|
269
|
+
>
|
270
|
+
class BlogController < Applica*tionController
|
271
|
+
< app/controllers/application.rb ~
|
272
|
+
>
|
273
|
+
class ApplicationController < ActionCont*roller::Base
|
274
|
+
< .../action_controller/base.rb ~
|
275
|
+
>
|
276
|
+
fixtures :pos*ts
|
277
|
+
< test/fixtures/posts.yml ~
|
278
|
+
>
|
279
|
+
layout :pri*nt
|
280
|
+
< app/views/layouts/print.rhtml ~
|
281
|
+
>
|
282
|
+
<%= link_to "New", new_comme*nt_path %>
|
283
|
+
< app/controllers/comments_controller.rb (jumps to def new) ~
|
284
|
+
|
285
|
+
In the last example, the controller and action for the named route are
|
286
|
+
determined by evaluating routes.rb as Ruby and doing some introspection. This
|
287
|
+
means code from the application is executed. Keep this in mind when
|
288
|
+
navigating unfamiliar applications.
|
289
|
+
|
290
|
+
Alternate and Related Files ~
|
291
|
+
*rails-alternate-related*
|
292
|
+
Two commands, :A and :R, are used quickly jump to an "alternate" and a
|
293
|
+
"related" file, defined below.
|
294
|
+
|
295
|
+
*rails-:A* *rails-:AE* *rails-:AS* *rails-:AV* *rails-:AT*
|
296
|
+
:A These commands were picked to mimic Michael Sharpe's
|
297
|
+
:AE a.vim. Briefly, they edit the "alternate" file, in
|
298
|
+
:AS either the same window (:A and :AE), a new split
|
299
|
+
:AV window (:AS), a new vertically split window (:AV), or
|
300
|
+
:AT a new tab (:AT). A mapping for :A is [f .
|
301
|
+
|
302
|
+
*rails-:R* *rails-:RE* *rails-:RS* *rails-:RV* *rails-:RT*
|
303
|
+
:R These are similar |rails-:A| and friends above, only
|
304
|
+
:RE they jump to the "related" file rather than the
|
305
|
+
:RS "alternate." A mapping for :R is ]f .
|
306
|
+
:RV
|
307
|
+
:RT
|
308
|
+
|
309
|
+
*rails-alternate* *rails-related*
|
310
|
+
The alternate file is most frequently the test file, though there are
|
311
|
+
exceptions. The related file varies, and is sometimes dependent on current
|
312
|
+
location in the file. For example, when editing a controller, the related
|
313
|
+
file is template for the method currently being edited.
|
314
|
+
|
315
|
+
The easiest way to learn these commands is to experiment. A few examples of
|
316
|
+
alternate and related files follow:
|
317
|
+
|
318
|
+
Current file Alternate file Related file ~
|
319
|
+
model unit test related migration
|
320
|
+
controller (in method) functional test template (view)
|
321
|
+
template (view) helper controller (jump to method)
|
322
|
+
migration previous migration next migration
|
323
|
+
config/routes.rb config/database.yml config/environment.rb
|
324
|
+
|
325
|
+
Suggestions for further contexts to consider for the alternate file, related
|
326
|
+
file, and file under the cursor are welcome. They are subtly tweaked from
|
327
|
+
release to release.
|
328
|
+
|
329
|
+
For the less common cases, a more deliberate set of commands are provided.
|
330
|
+
Each of the following takes an optional argument (with tab completion) but
|
331
|
+
defaults to a reasonable guess that follows Rails conventions. For example,
|
332
|
+
when editing app/models/employee.rb, :Rcontroller will default to
|
333
|
+
app/controllers/employees_controller.rb. The controller and model options,
|
334
|
+
ideally set from |rails-modelines|, can override the mapping from model
|
335
|
+
related files to controller related files (Rset controller=hiring) and vice
|
336
|
+
versa (Rset model=employee). See |rails-:Rset|.
|
337
|
+
|
338
|
+
Each of the following commands has variants for splitting, vertical splitting
|
339
|
+
and opening in a new tab. For :Rmodel, those variants would be :RSmodel,
|
340
|
+
:RVmodel, and :RTmodel. There is also :REmodel which is a synonym for :Rmodel
|
341
|
+
(future versions might allow customization of the behavior of :Rmodel).
|
342
|
+
|
343
|
+
|
344
|
+
Model Navigation Commands ~
|
345
|
+
*rails-model-navigation*
|
346
|
+
The default for model navigation commands is the current model, if it can be
|
347
|
+
determined. For example, test/unit/post_test.rb would have a current model
|
348
|
+
of post. Otherwise, if a controller name can be determined, said controller
|
349
|
+
name will be singularized and used. To override this, use a command or
|
350
|
+
modeline like: >
|
351
|
+
Rset model=comment
|
352
|
+
|
353
|
+
:Rmodel |rails-:Rmodel|
|
354
|
+
:Rmigration |rails-:Rmigration|
|
355
|
+
:Robserver |rails-:Robserver|
|
356
|
+
:Rfixtures |rails-:Rfixtures|
|
357
|
+
:Runittest |rails-:Runittest|
|
358
|
+
|
359
|
+
*rails-:Rmodel*
|
360
|
+
:Rmodel [{name}] Edit the specified model.
|
361
|
+
|
362
|
+
*rails-:Rmigration*
|
363
|
+
:Rmigration [{pattern}] If {pattern} is a number, find the migration for that
|
364
|
+
particular set of digits, zero-padding if necessary.
|
365
|
+
Otherwise, find the newest migration containing the
|
366
|
+
given pattern. The pattern defaults to the current
|
367
|
+
model name, pluralized. So when editing the Post
|
368
|
+
model, :Rmigration with no arguments might find
|
369
|
+
create_posts.rb, or add_date_to_posts.rb.
|
370
|
+
|
371
|
+
*rails-:Robserver*
|
372
|
+
:Robserver [{name}] Find the observer with a name like
|
373
|
+
{model}_observer.rb. When in an observer, most
|
374
|
+
commands (like :Rmodel) will seek based on the
|
375
|
+
observed model ({model}) and not the actual observer
|
376
|
+
({model}_observer). However, for the command
|
377
|
+
:Runittest, a file of the form
|
378
|
+
{model}_observer_test.rb will be found.
|
379
|
+
|
380
|
+
*rails-:Rfixtures*
|
381
|
+
:Rfixtures [{name}] Edit the fixtures for the given model. If an argument
|
382
|
+
is given, it must be pluralized, like the final
|
383
|
+
filename (this may change in the future). If omitted,
|
384
|
+
the current model is pluralized automatically. An
|
385
|
+
optional extension can be given, to distinguish
|
386
|
+
between YAML and CSV fixtures.
|
387
|
+
|
388
|
+
*rails-:Runittest*
|
389
|
+
:Runittest [{name}] Edit the unit test for the specified model.
|
390
|
+
|
391
|
+
Controller Navigation Commands ~
|
392
|
+
*rails-controller-navigation*
|
393
|
+
The default for controller navigation commands is the current controller, if
|
394
|
+
it can be determined. For example, test/functional/blog_test.rb would have a
|
395
|
+
current controller of blog. Otherwise, if a model name can be determined,
|
396
|
+
said model name will be pluralized and used. To override this, use a command
|
397
|
+
or modeline like: >
|
398
|
+
Rset controller=blog
|
399
|
+
|
400
|
+
:Rcontroller |rails-:Rcontroller|
|
401
|
+
:Rhelper |rails-:Rhelper|
|
402
|
+
:Rview |rails-:Rview|
|
403
|
+
:Rlayout |rails-:Rlayout|
|
404
|
+
:Rfunctionaltest |rails-:Rfunctionaltest|
|
405
|
+
|
406
|
+
*rails-:Rcontroller*
|
407
|
+
:Rcontroller [{name}] Edit the specified controller.
|
408
|
+
|
409
|
+
*rails-:Rhelper*
|
410
|
+
:Rhelper [{name}] Edit the helper for the specified controller.
|
411
|
+
|
412
|
+
*rails-:Rview*
|
413
|
+
:Rview [[{controller}/]{view}]
|
414
|
+
Edit the specified view. The controller will default
|
415
|
+
sensibly, and the view name can be omitted when
|
416
|
+
editing a method of a controller. If a view name is
|
417
|
+
given with an extension, a new file will be created.
|
418
|
+
This is a quick way to create a new view.
|
419
|
+
|
420
|
+
*rails-:Rlayout*
|
421
|
+
:Rlayout [{name}] Edit the specified layout. Defaults to the layout for
|
422
|
+
the current controller, or the application layout if
|
423
|
+
that cannot be found. A new layout will be created if
|
424
|
+
an extension is given.
|
425
|
+
|
426
|
+
*rails-:Rapi*
|
427
|
+
:Rapi [{name}] Edit the API for the specified controller. This
|
428
|
+
command is deprecated; add it yourself with
|
429
|
+
|:Rcommand| if you still desire it.
|
430
|
+
|
431
|
+
*rails-:Rfunctionaltest*
|
432
|
+
:Rfunctionaltest [{name}]
|
433
|
+
Edit the functional test for the specified controller.
|
434
|
+
|
435
|
+
Miscellaneous Navigation Commands ~
|
436
|
+
*rails-misc-navigation*
|
437
|
+
|
438
|
+
The following commands are not clearly associated with models or controllers.
|
439
|
+
|
440
|
+
:Rstylesheet |rails-:Rstylesheet|
|
441
|
+
:Rjavascript |rails-:Rjavascript|
|
442
|
+
:Rplugin |rails-:Rplugin|
|
443
|
+
:Rlib |rails-:Rlib|
|
444
|
+
:Rtask |rails-:Rtask|
|
445
|
+
:Rintegrationtest |rails-:Rintegrationtest|
|
446
|
+
|
447
|
+
*rails-:Rstylesheet*
|
448
|
+
:Rstylesheet [{name}] Edit the stylesheet for the specified name, defaulting
|
449
|
+
to the current controller's name.
|
450
|
+
|
451
|
+
*rails-:Rjavascript*
|
452
|
+
:Rjavascript [{name}] Edit the javascript for the specified name, defaulting
|
453
|
+
to the current controller's name.
|
454
|
+
|
455
|
+
*rails-:Rplugin*
|
456
|
+
:Rplugin {plugin}[/{path}]
|
457
|
+
Edits a file within a plugin. If the path to the file
|
458
|
+
is omitted, it defaults to init.rb.
|
459
|
+
|
460
|
+
*rails-:Rlib*
|
461
|
+
:Rlib {name} Edit the library from the lib directory for the
|
462
|
+
specified name. If the current file is part of a
|
463
|
+
plugin, the libraries from that plugin can be
|
464
|
+
specified as well.
|
465
|
+
|
466
|
+
*rails-:Rtask*
|
467
|
+
:Rtask [{name}] Edit the .rake file from lib/tasks for the specified
|
468
|
+
name. If the current file is part of a plugin, the
|
469
|
+
tasks for that plugin can be specified as well. If no
|
470
|
+
argument is given, either the current plugin's
|
471
|
+
Rakefile or the application Rakefile will be edited.
|
472
|
+
|
473
|
+
*rails-:Rintegrationtest*
|
474
|
+
:Rintegrationtest [{name}]
|
475
|
+
Edit the integration test specified. The default
|
476
|
+
is based on the current controller or model, with no
|
477
|
+
singularization or pluralization done.
|
478
|
+
|
479
|
+
Custom Navigation Commands ~
|
480
|
+
*rails-custom-navigation*
|
481
|
+
|
482
|
+
It is also possible to create custom navigation commands. This is best done
|
483
|
+
in an initialization routine of some sort (e.g., an autocommand); see
|
484
|
+
|rails-configuration| for details.
|
485
|
+
|
486
|
+
*rails-:Rcommand*
|
487
|
+
:Rcommand [options] {name} [{path} ...]
|
488
|
+
Create a navigation command with the supplied
|
489
|
+
name, looking in the supplied paths, using the
|
490
|
+
supplied options. The -suffix option specifies what
|
491
|
+
suffix to filter on, and strip from the filename, and
|
492
|
+
defaults to -suffix=.rb . The -glob option specifies
|
493
|
+
a file glob to use to find files, _excluding_ the
|
494
|
+
suffix. Useful values include -glob=* and -glob=**/*.
|
495
|
+
The -default option specifies a default argument (not
|
496
|
+
a full path). If it is specified as -default=model(),
|
497
|
+
-default=controller(), or -default=both(), the current
|
498
|
+
model, controller, or both (as with :Rintegrationtest)
|
499
|
+
is used as a default.
|
500
|
+
|
501
|
+
:Rcommand is still under development and far from fully documented, but the
|
502
|
+
following examples should illustrate the basics:
|
503
|
+
>
|
504
|
+
Rcommand api app/apis -glob=**/* -suffix=_api.rb
|
505
|
+
Rcommand config config -glob=*.* -suffix= -default=routes.rb
|
506
|
+
Rcommand environment config/environments -default=../environment
|
507
|
+
Rcommand concern app/concerns -glob=**/*
|
508
|
+
|
509
|
+
Finally, one Vim feature that proves helpful in conjunction with all of the
|
510
|
+
above is |CTRL-^|. This keystroke edits the previous file, and is helpful to
|
511
|
+
back out of any of the above commands.
|
512
|
+
|
513
|
+
==============================================================================
|
514
|
+
SCRIPT WRAPPERS *rails-scripts*
|
515
|
+
|
516
|
+
The following commands are wrappers around the scripts in the script directory
|
517
|
+
of the Rails application. Most have extra features beyond calling the script.
|
518
|
+
A limited amount of completion with <Tab> is supported.
|
519
|
+
|
520
|
+
*rails-:Rscript*
|
521
|
+
:Rscript {script} {options}
|
522
|
+
Call ruby script/{script} {options}.
|
523
|
+
|
524
|
+
*rails-:Rconsole*
|
525
|
+
:Rconsole {options} Start script/console. On Windows it will be launched
|
526
|
+
in the background with |!start|. In the terminal
|
527
|
+
version GNU Screen is used if it is running and
|
528
|
+
|g:rails_gnu_screen| is set.
|
529
|
+
|
530
|
+
*rails-:Rrunner*
|
531
|
+
:[range]Rrunner {code} Executes {code} with script/runner. Differs from
|
532
|
+
:Rscript runner {code} in that the code is passed as
|
533
|
+
one argument. Also, |system()| is used instead of
|
534
|
+
|:!|. This is to help eliminate annoying "Press
|
535
|
+
ENTER" prompts. If a line number is given in the
|
536
|
+
range slot, the output is pasted into the buffer after
|
537
|
+
that line.
|
538
|
+
|
539
|
+
*rails-:Rp*
|
540
|
+
:[range]Rp {code} Like :Rrunner, but call the Ruby p method on the
|
541
|
+
result. Literally "p begin {code} end".
|
542
|
+
|
543
|
+
*rails-:Rpp* *rails-:Ry*
|
544
|
+
:[range]Rpp {code} Like :Rp, but with pp (pretty print) or y (YAML
|
545
|
+
:[range]Ry {code} output).
|
546
|
+
|
547
|
+
*rails-:Rgenerate*
|
548
|
+
:Rgenerate {options} Calls script/generate {options}, and then edits the
|
549
|
+
first file generated. Respects |g:rails_subversion|.
|
550
|
+
|
551
|
+
*rails-:Rdestroy*
|
552
|
+
:Rdestroy {options} Calls script/destroy {options}. Respects
|
553
|
+
|g:rails_subversion|.
|
554
|
+
|
555
|
+
*rails-:Rserver*
|
556
|
+
:Rserver {options} Launches script/server {options} in the background.
|
557
|
+
On win32, this means |!start|. On other systems, this
|
558
|
+
uses the --daemon option.
|
559
|
+
|
560
|
+
*rails-:Rserver!*
|
561
|
+
:Rserver! {options} Same as |:Rserver|, only first attempts to kill any
|
562
|
+
other server using the same port. On non-Windows
|
563
|
+
systems, lsof must be installed for this to work.
|
564
|
+
|
565
|
+
==============================================================================
|
566
|
+
REFACTORING HELPERS *rails-refactoring*
|
567
|
+
|
568
|
+
A few features are dedicated to helping you refactor your code.
|
569
|
+
|
570
|
+
Partial Extraction ~
|
571
|
+
*rails-partials*
|
572
|
+
|
573
|
+
The :Rextract command can be used to extract a partial to a new file.
|
574
|
+
|
575
|
+
*rails-:Rextract*
|
576
|
+
:[range]Rextract [{controller}/]{name}
|
577
|
+
Create a {name} partial from [range] lines (default:
|
578
|
+
current line).
|
579
|
+
|
580
|
+
*rails-:Rpartial*
|
581
|
+
:[range]Rpartial [{controller}/]{name}
|
582
|
+
Deprecated alias for :Rextract.
|
583
|
+
|
584
|
+
If this is your file, in app/views/blog/show.rhtml: >
|
585
|
+
|
586
|
+
1 <div>
|
587
|
+
2 <h2><%= @post.title %></h2>
|
588
|
+
3 <p><%= @post.body %></p>
|
589
|
+
4 </div>
|
590
|
+
|
591
|
+
And you issue this command: >
|
592
|
+
|
593
|
+
:2,3Rextract post
|
594
|
+
|
595
|
+
Your file will change to this: >
|
596
|
+
|
597
|
+
1 <div>
|
598
|
+
2 <%= render :partial => 'post' %>
|
599
|
+
3 </div>
|
600
|
+
|
601
|
+
And app/views/blog/_post.rhtml will now contain: >
|
602
|
+
|
603
|
+
1 <h2><%= post.title %></h2>
|
604
|
+
2 <p><%= post.body %></p>
|
605
|
+
|
606
|
+
As a special case, if the file had looked like this: >
|
607
|
+
|
608
|
+
1 <% for object in @posts -%>
|
609
|
+
2 <h2><%= object.title %></h2>
|
610
|
+
3 <p><%= object.body %></p>
|
611
|
+
4 <% end -%>
|
612
|
+
<
|
613
|
+
The end result would have been this: >
|
614
|
+
|
615
|
+
1 <%= render :partial => 'post', :collection => @posts %>
|
616
|
+
<
|
617
|
+
The easiest way to choose what to extract is to use |linewise-visual| mode.
|
618
|
+
Then, a simple >
|
619
|
+
:'<,'>Rextract blog/post
|
620
|
+
will suffice. (Note the use of a controller name in this example.)
|
621
|
+
|
622
|
+
Migration Inversion ~
|
623
|
+
*rails-migrations* *rails-:Rinvert*
|
624
|
+
:Rinvert In a migration, rewrite the self.up method into a
|
625
|
+
self.down method. If self.up is empty, the process is
|
626
|
+
reversed. This chokes on more complicated
|
627
|
+
instructions, but works reasonably well for simple
|
628
|
+
calls to create_table, add_column, and the like.
|
629
|
+
|
630
|
+
==============================================================================
|
631
|
+
INTEGRATION *rails-integration*
|
632
|
+
|
633
|
+
Having one foot in Rails and one in Vim, rails.vim has two worlds with which
|
634
|
+
to interact.
|
635
|
+
|
636
|
+
Integration with the Vim Universe ~
|
637
|
+
*rails-vim-integration*
|
638
|
+
|
639
|
+
A handful of Vim plugins are enhanced by rails.vim. All plugins mentioned can
|
640
|
+
be found at http://www.vim.org/. Cream and GUI menus (for lack of a better
|
641
|
+
place) are also covered in this section.
|
642
|
+
|
643
|
+
*rails-:Rproject* *rails-project*
|
644
|
+
:Rproject [{file}] This command is only provided when the |project|
|
645
|
+
plugin is installed. Invoke :Project (typically
|
646
|
+
without an argument), and search for the root of the
|
647
|
+
current Rails application. If it is not found, create
|
648
|
+
a new project, with appropriate directories (app,
|
649
|
+
etc., but not vendor).
|
650
|
+
|
651
|
+
*rails-:Rproject!*
|
652
|
+
:Rproject! [{file}] Same as :Rproject, only delete existing project if it
|
653
|
+
exists and recreate it. The logic to delete the old
|
654
|
+
project is convoluted and possibly erroneous; report
|
655
|
+
any problems to the |rails-plugin-author|. A handy
|
656
|
+
mapping might look something like: >
|
657
|
+
autocmd User Rails map <buffer> <F6> :Rproject!|silent w<CR>
|
658
|
+
< As a bonus, this command organizes views into separate
|
659
|
+
directories for easier navigation. The downside of
|
660
|
+
this is that you will have to regenerate your project
|
661
|
+
each time you add another view directory (which is why
|
662
|
+
this command recreates your project each time!).
|
663
|
+
|
664
|
+
*rails-:Rdbext* *rails-dbext*
|
665
|
+
:Rdbext [{environment}] This command is only provided when the |dbext| plugin
|
666
|
+
is installed. Loads the {environment} configuration
|
667
|
+
(defaults to $RAILS_ENV or development) from
|
668
|
+
config/database.yml and uses it to configure dbext.
|
669
|
+
The configuration is cached until a different Rails
|
670
|
+
application is edited. This command is called for you
|
671
|
+
automatically when |g:rails_dbext| is set (default on
|
672
|
+
non-Windows systems).
|
673
|
+
|
674
|
+
*rails-:Rdbext!*
|
675
|
+
:Rdbext! [{environment}]
|
676
|
+
Load the database configuration as above, and then
|
677
|
+
attempt a CREATE DATABASE for it. This is primarily
|
678
|
+
useful for demonstrations.
|
679
|
+
|
680
|
+
*rails-surround*
|
681
|
+
The |surround| plugin available from vim.org enables adding and removing
|
682
|
+
"surroundings" like parentheses, quotes, and HTML tags. Even by itself, it is
|
683
|
+
quite useful for Rails development, particularly eRuby editing. When coupled
|
684
|
+
with this plugin, a few additional replacement surroundings are available in
|
685
|
+
eRuby files. See the |surround| documentation for details on how to use them.
|
686
|
+
The table below uses ^ to represent the position of the surrounded text.
|
687
|
+
|
688
|
+
Key Surrounding ~
|
689
|
+
= <%= ^ %>
|
690
|
+
- <% ^ -%>
|
691
|
+
# <%# ^ %>
|
692
|
+
<C-E> <% ^ -%>\n<% end -%>
|
693
|
+
|
694
|
+
The last surrounding is particularly useful in insert mode with the following
|
695
|
+
map in one's vimrc. Use Alt+o to open a new line below the current one. This
|
696
|
+
works nicely even in a terminal (where most alt/meta maps will fail) because
|
697
|
+
most terminals send <M-o> as <Esc>o anyways.
|
698
|
+
>
|
699
|
+
imap <M-o> <Esc>o
|
700
|
+
<
|
701
|
+
One can also use the <C-E> surrounding in a plain Ruby file to append a bare
|
702
|
+
"end" on the following line.
|
703
|
+
|
704
|
+
*rails-cream*
|
705
|
+
This plugin provides a few additional key bindings if it is running under
|
706
|
+
Cream, the user friendly editor which uses Vim as a back-end. Ctrl+Enter
|
707
|
+
finds the file under the cursor (as in |rails-gf|), and Alt+[ and Alt+] find
|
708
|
+
the alternate (|rails-alternate|) and related (|rails-related|) files.
|
709
|
+
|
710
|
+
*rails-menu*
|
711
|
+
If the GUI is running, a menu for several commonly used features is provided.
|
712
|
+
Also on this menu is a list of recently accessed projects. This list of
|
713
|
+
projects can persist across restarts if a 'viminfo' flag is set to enable
|
714
|
+
retaining certain global variables. If this interests you, add something like
|
715
|
+
the following to your vimrc: >
|
716
|
+
set viminfo^=!
|
717
|
+
<
|
718
|
+
Integration with the Rails Universe ~
|
719
|
+
*rails-rails-integration*
|
720
|
+
The general policy of rails.vim is to focus exclusively on the Ruby on Rails
|
721
|
+
core. Supporting plugins and other add-ons to Rails has the potential to
|
722
|
+
rapidly get out of hand. However, a few pragmatic exceptions have been made.
|
723
|
+
|
724
|
+
*rails-template-types*
|
725
|
+
Commands like :Rview use a hardwired list of extensions (rhtml, rjs, etc.)
|
726
|
+
when searching for files. In order to facilitate working with non-standard
|
727
|
+
template types, several popular extensions are featured in this list,
|
728
|
+
including haml, liquid, and mab (markaby). These extensions will disappear
|
729
|
+
once a related configuration option is added to rails.vim.
|
730
|
+
|
731
|
+
*rails-rspec*
|
732
|
+
Support for RSpec is currently experimental and incomplete, with only a
|
733
|
+
handful of features being implemented. :A knows about specs and will jump to
|
734
|
+
them, but only if no test file is found. The associated controller or model
|
735
|
+
of a spec is detected, so all navigation commands should work as expected
|
736
|
+
inside a spec file. :Rfixtures will find spec fixtures, but the extension is
|
737
|
+
mandatory and tab completion will not work. :Rake will run the currently
|
738
|
+
edited spec.
|
739
|
+
|
740
|
+
While there are currently no built-in dedicated RSpec navigation commands, you
|
741
|
+
can approximate your own with |:Rcommand|.
|
742
|
+
>
|
743
|
+
Rcommand specmodel spec/models -glob=**/*
|
744
|
+
\ -suffix=_spec.rb -default=model()
|
745
|
+
Rcommand spechelper spec/helpers -glob=**/*
|
746
|
+
\ -suffix=_helper_spec.rb -default=controller()
|
747
|
+
Rcommand speccontroller spec/controllers -glob=**/*
|
748
|
+
\ -suffix=_controller_spec.rb -default=controller()
|
749
|
+
Rcommand specview spec/views -glob=**/* -suffix=_view_spec.rb
|
750
|
+
<
|
751
|
+
==============================================================================
|
752
|
+
ABBREVIATIONS *rails-abbreviations* *rails-snippets*
|
753
|
+
|
754
|
+
Abbreviations are still experimental. They may later be extracted into a
|
755
|
+
separate plugin, or removed entirely.
|
756
|
+
|
757
|
+
*rails-:Rabbrev*
|
758
|
+
:Rabbrev List all Rails abbreviations.
|
759
|
+
|
760
|
+
:Rabbrev {abbr} {expn} [{extra}]
|
761
|
+
Define a new Rails abbreviation. {extra} is permitted
|
762
|
+
if and only if {expn} ends with "(".
|
763
|
+
|
764
|
+
*rails-:Rabbrev!*
|
765
|
+
:Rabbrev! {abbr} Remove an abbreviation.
|
766
|
+
|
767
|
+
Rails abbreviations differ from regular abbreviations in that they only expand
|
768
|
+
after a <C-]> (see |i_CTRL-]|) or a <Tab> (if <Tab> does not work, it is
|
769
|
+
likely mapped by another plugin). If the abbreviation ends in certain
|
770
|
+
punctuation marks, additional expansions are possible. A few examples will
|
771
|
+
hopefully clear this up (all of the following are enabled by default in
|
772
|
+
appropriate file types).
|
773
|
+
|
774
|
+
Command Sequence typed Resulting text ~
|
775
|
+
Rabbrev rp( render :partial\ => rp( render(:partial =>
|
776
|
+
Rabbrev rp( render :partial\ => rp<Tab> render :partial =>
|
777
|
+
Rabbrev vs( validates_size_of vs( validates_size_of(
|
778
|
+
Rabbrev pa[ params pa[:id] params[:id]
|
779
|
+
Rabbrev pa[ params pa<C-]> params
|
780
|
+
Rabbrev pa[ params pa.inspect params.inspect
|
781
|
+
Rabbrev AR:: ActionRecord AR::Base ActiveRecord::Base
|
782
|
+
Rabbrev :a :action\ =>\ render :a<Tab> render :action =>
|
783
|
+
|
784
|
+
In short, :: expands on :, ( expands on (, and [ expands on both . and [.
|
785
|
+
These trailing punctuation marks are NOT part of the final abbreviation, and
|
786
|
+
you cannot have two mappings that differ only by punctuation.
|
787
|
+
|
788
|
+
You must escape spaces in your expansion, either as "\ " or as "<Space>". For
|
789
|
+
an abbreviation ending with "(", you may define where to insert the
|
790
|
+
parenthesis by splitting the expansion into two parts (divided by an unescaped
|
791
|
+
space).
|
792
|
+
|
793
|
+
Many abbreviations abbreviations are provided by default: use :Rabbrev to list
|
794
|
+
them. They vary depending on the type of file (models have different
|
795
|
+
abbreviations than controllers). There is one "smart" abbreviation, :c, which
|
796
|
+
expands to ":controller => ", ":collection => ", or ":conditions => "
|
797
|
+
depending on context.
|
798
|
+
|
799
|
+
==============================================================================
|
800
|
+
SYNTAX HIGHLIGHTING *rails-syntax*
|
801
|
+
|
802
|
+
Syntax highlighting is by and large a transparent process. For the full
|
803
|
+
effect, however, you need a colorscheme which accentuates rails.vim
|
804
|
+
extensions. One such colorscheme is vividchalk, available from vim.org.
|
805
|
+
|
806
|
+
The following is a summary of the changes made by rails.vim to the standard
|
807
|
+
syntax highlighting.
|
808
|
+
|
809
|
+
*rails-syntax-keywords*
|
810
|
+
Rails specific keywords are highlighted in a filetype specific manner. For
|
811
|
+
example, in a model, has_many is highlighted, whereas in a controller,
|
812
|
+
before_filter is highlighted. A wide variety of syntax groups are used but
|
813
|
+
they all link by default to railsMethod.
|
814
|
+
|
815
|
+
If you feel a method has been wrongfully omitted, submit it to the
|
816
|
+
|rails-plugin-author|.
|
817
|
+
|
818
|
+
*rails-@params* *rails-syntax-deprecated*
|
819
|
+
Certain deprecated syntax (like @params and render_text) is highlighted as an
|
820
|
+
error. If you trigger this highlighting, generally it means you need to
|
821
|
+
update your code.
|
822
|
+
|
823
|
+
*rails-syntax-classes*
|
824
|
+
Models, helpers, and controllers are given special highlighting. Depending on
|
825
|
+
the version of Vim installed, you may need a rails.vim aware colorscheme in
|
826
|
+
order to see this. Said colorscheme needs to provide highlighting for the
|
827
|
+
railsUserClass syntax group.
|
828
|
+
|
829
|
+
The class names are determined by camelizing filenames from certain
|
830
|
+
directories of your application. If app/models/line_item.rb exists, the class
|
831
|
+
"LineItem" will be highlighted.
|
832
|
+
|
833
|
+
The list of classes is refreshed automatically after certain commands like
|
834
|
+
|:Rgenerate|. Use |:Rrefresh| to trigger the process manually.
|
835
|
+
|
836
|
+
*rails-syntax-assertions*
|
837
|
+
If you define custom assertions in test_helper.rb, these will be highlighted
|
838
|
+
in your tests. These are found by scanning test_helper.rb for lines of the
|
839
|
+
form " def assert_..." and extracting the method name. The railsUserMethod
|
840
|
+
syntax group is used. The list of assertions can be refreshed with
|
841
|
+
|:Rrefresh|.
|
842
|
+
|
843
|
+
*rails-syntax-strings*
|
844
|
+
In the following line of code, the "?" in the conditions clause and the "ASC"
|
845
|
+
in the order clause will be highlighted: >
|
846
|
+
Post.find(:all, :conditions => ["body like ?","%e%"] :order => "title ASC")
|
847
|
+
<
|
848
|
+
A string literal using %Q<> delimiters will have its contents highlighted as
|
849
|
+
HTML. This is sometimes useful when writing helpers. >
|
850
|
+
link = %Q<<a href="http://www.vim.org">Vim</a>>
|
851
|
+
<
|
852
|
+
*rails-syntax-yaml*
|
853
|
+
YAML syntax highlighting has been extended to highlight eRuby, which can be
|
854
|
+
used in most Rails YAML files (including database.yml and fixtures).
|
855
|
+
|
856
|
+
==============================================================================
|
857
|
+
MANAGED VIM OPTIONS *rails-options*
|
858
|
+
|
859
|
+
The following options are set local to buffers where the plugin is active.
|
860
|
+
|
861
|
+
*rails-'shiftwidth'* *rails-'sw'*
|
862
|
+
*rails-'softtabstop'* *rails-'sts'*
|
863
|
+
*rails-'expandtab'* *rails-'et'*
|
864
|
+
A value of 2 is used for 'shiftwidth' (and 'softtabstop'), and 'expandtab' is
|
865
|
+
enabled. This is a strong convention in Rails, so the conventional wisdom
|
866
|
+
that this is a user preference has been ignored.
|
867
|
+
|
868
|
+
*rails-'path'* *rails-'pa'*
|
869
|
+
All the relevant directories from your application are added to your 'path'.
|
870
|
+
This makes it easy to access a buried file: >
|
871
|
+
:find blog_controller.rb
|
872
|
+
<
|
873
|
+
*rails-'suffixesadd'* *rails-'sua'*
|
874
|
+
This is filetype dependent, but typically includes .rb, .rhtml, and several
|
875
|
+
others. This allows shortening the above example: >
|
876
|
+
:find blog_controller
|
877
|
+
<
|
878
|
+
*rails-'includeexpr'* *rails-'inex'*
|
879
|
+
The 'includeexpr' option is set to enable the magic described in |rails-gf|.
|
880
|
+
|
881
|
+
*rails-'statusline'* *rails-'stl'*
|
882
|
+
Useful information is added to the 'statusline', when |g:rails_statusline| is
|
883
|
+
enabled.
|
884
|
+
|
885
|
+
*rails-'makeprg'* *rails-'mp'*
|
886
|
+
*rails-'errorformat'* *rails-'efm'*
|
887
|
+
Rake is used as the 'makeprg', so |:make| will work as expected. Also,
|
888
|
+
'errorformat' is set appropriately to handle your tests.
|
889
|
+
|
890
|
+
*rails-'filetype'* *rails-'ft'*
|
891
|
+
The 'filetype' is sometimes adjusted for Rails files. Most notably, *.rxml
|
892
|
+
and *.rjs are treated as Ruby files, and files that have been falsely
|
893
|
+
identified as Mason sources are changed back to eRuby files (but only when
|
894
|
+
they are part of a Rails application).
|
895
|
+
|
896
|
+
*rails-'completefunc'* *rails-'cfu'*
|
897
|
+
A 'completefunc' is provided (if not already set). It is very simple, as it
|
898
|
+
uses syntax highlighting to make its guess. See |i_CTRL-X_CTRL-U|.
|
899
|
+
|
900
|
+
==============================================================================
|
901
|
+
CONFIGURATION *rails-configuration*
|
902
|
+
|
903
|
+
Very little configuration is actually required; this plugin automatically
|
904
|
+
detects your Rails application and adjusts Vim sensibly.
|
905
|
+
|
906
|
+
*rails-:autocmd* *rails-autocommands*
|
907
|
+
If you would like to set your own custom Vim settings whenever a Rails file is
|
908
|
+
loaded, you can use an autocommand like the following in your vimrc: >
|
909
|
+
autocmd User Rails silent! Rlcd
|
910
|
+
autocmd User Rails map <buffer> <F9> :Rake<CR>
|
911
|
+
You can also have autocommands that only apply to certain types of files.
|
912
|
+
These are based off the information shown in the 'statusline' (see
|
913
|
+
|rails-'statusline'|), with hyphens changed to periods. A few examples: >
|
914
|
+
autocmd User Rails.controller* iabbr <buffer> wsn wsdl_service_name
|
915
|
+
autocmd User Rails.model.arb* iabbr <buffer> vfo validates_format_of
|
916
|
+
autocmd User Rails.view.rhtml* imap <buffer> <C-Z> <%= %><C-O>3h
|
917
|
+
End all such Rails autocommands with asterisks, even if you have an exact
|
918
|
+
specification. There is also a filename matching syntax: >
|
919
|
+
autocmd User Rails/db/schema.rb Rset task=db:schema:dump
|
920
|
+
autocmd User Rails/**/foo_bar.rb Rabbrev FB:: FooBar
|
921
|
+
Use the filetype based syntax whenever possible, reserving the filename based
|
922
|
+
syntax for more advanced cases.
|
923
|
+
|
924
|
+
*macros/rails.vim*
|
925
|
+
If you have several commands to run on initialization for all file types, they
|
926
|
+
can be placed in a "macros/rails.vim" file in the 'runtimepath' (for example,
|
927
|
+
"~/.vim/macros/rails.vim"). This file is sourced by rails.vim each time a
|
928
|
+
Rails file is loaded.
|
929
|
+
|
930
|
+
*config/rails.vim*
|
931
|
+
If you have settings particular to a specific project, they can be put in a
|
932
|
+
config/rails.vim file in the root directory of the application. The file is
|
933
|
+
sourced in the |sandbox| for security reasons. This only works in Vim 7 or
|
934
|
+
newer.
|
935
|
+
|
936
|
+
*rails-:Rset*
|
937
|
+
:Rset {option}[={value}]
|
938
|
+
Query or set a local option. This command may be
|
939
|
+
called directly, from an autocommand, or from
|
940
|
+
config/rails.vim.
|
941
|
+
|
942
|
+
Options may be set set in one of four scopes, which my be indicated by an
|
943
|
+
optional prefix. These scopes determine how broadly an option will apply.
|
944
|
+
Generally, the default scope is sufficient
|
945
|
+
|
946
|
+
Scope Description ~
|
947
|
+
a: All files in one Rails application
|
948
|
+
b: Buffer (file) specific
|
949
|
+
g: Global to all applications
|
950
|
+
l: Local to method (same as b: in non-Ruby files)
|
951
|
+
|
952
|
+
Options are shown below with their default scope, which should be omitted.
|
953
|
+
While you may override the scope with a prefix, this is rarely necessary and
|
954
|
+
oftentimes useless. (For example, setting g:task is useless because the
|
955
|
+
default rake task will apply before considering this option.)
|
956
|
+
|
957
|
+
Option Meaning ~
|
958
|
+
b:alternate Custom alternate file for :A, relative to the Rails root
|
959
|
+
b:controller Default controller for certain commands (e.g., :Rhelper)
|
960
|
+
b:model Default model for certain commands (e.g., :Rfixtures)
|
961
|
+
l:preview URL stub for :Rpreview (e.g., blog/show/1)
|
962
|
+
b:task Default task used with :Rake
|
963
|
+
l:related Custom related file for :R, relative to the Rails root
|
964
|
+
a:root_url Root URL for commands like :Rpreview
|
965
|
+
a:ruby_fork_port Experimental: use ruby_fork on given port to speed things up
|
966
|
+
|
967
|
+
Examples: >
|
968
|
+
:Rset root_url=http://localhost:12345
|
969
|
+
:Rset related=app/views/blog/edit.rhtml preview=blog/edit/1
|
970
|
+
:Rset alternate=app/models/
|
971
|
+
:Rset l:task=preview " Special pseudo-task for :Rake
|
972
|
+
|
973
|
+
Note the use of a scope prefix in the last example.
|
974
|
+
|
975
|
+
*rails-modelines*
|
976
|
+
If |g:rails_modelines| is enabled, these options can also be set from
|
977
|
+
modelines near the beginning or end of the file. These modelines will always
|
978
|
+
set buffer-local options; scope should never be specified. Examples: >
|
979
|
+
# Rset task=db:schema:load
|
980
|
+
<%# Rset alternate=app/views/layouts/application.rhtml %>
|
981
|
+
Modelines can also be local to a method. Example: >
|
982
|
+
def test_comment
|
983
|
+
# rset alternate=app/models/comment.rb
|
984
|
+
These two forms differ only in case.
|
985
|
+
|
986
|
+
Modelines are deprecated.
|
987
|
+
|
988
|
+
==============================================================================
|
989
|
+
GLOBAL SETTINGS *rails-global-settings*
|
990
|
+
|
991
|
+
A few global variables control the behavior of this plugin. In general, they
|
992
|
+
can be enabled by setting them to 1 in your vimrc, and disabled by setting
|
993
|
+
them to 0. >
|
994
|
+
let g:rails_some_option=1
|
995
|
+
let g:rails_some_option=0
|
996
|
+
Most of these should never need to be used. The few that might be interesting
|
997
|
+
are |g:rails_expensive|, |g:rails_subversion|, and |g:rails_default_database|.
|
998
|
+
|
999
|
+
*g:loaded_rails* >
|
1000
|
+
let g:loaded_rails=1
|
1001
|
+
Do not load the plugin. For emergency use only.
|
1002
|
+
|
1003
|
+
*g:rails_abbreviations*
|
1004
|
+
Enable Rails abbreviations. See |rails-abbreviations|. Enabled by default.
|
1005
|
+
|
1006
|
+
*g:rails_dbext* >
|
1007
|
+
let g:rails_dbext=1
|
1008
|
+
Enable integration with the dbext plugin, if it is installed. Defaults to the
|
1009
|
+
value of |g:rails_expensive|. When this option is set, dbext settings are
|
1010
|
+
automagically extracted from config/database.yml. Then, you can use features
|
1011
|
+
like table name completion and commands like >
|
1012
|
+
:Create database brablog_development
|
1013
|
+
:Select * from posts where title like '%Denmark%'
|
1014
|
+
Note that dbext is a complicated plugin, and may require additional
|
1015
|
+
configuration. See |dbext| (if installed) and |sql-completion-dynamic| (in
|
1016
|
+
Vim 7).
|
1017
|
+
|
1018
|
+
*g:rails_default_file* >
|
1019
|
+
let g:rails_default_file='config/database.yml'
|
1020
|
+
File to load when a new Rails application is created, or when loading an
|
1021
|
+
existing project from the menu. Defaults to the README.
|
1022
|
+
|
1023
|
+
*g:rails_default_database* >
|
1024
|
+
let g:rails_default_database='sqlite3'
|
1025
|
+
Database to use for new applications. Defaults to letting Rails decide.
|
1026
|
+
|
1027
|
+
*rails-slow* *g:rails_expensive* >
|
1028
|
+
let g:rails_expensive=1
|
1029
|
+
Enables or disables expensive (slow) features (typically involving calls to
|
1030
|
+
the Ruby interpreter). Recommended for moderately fast computers. This
|
1031
|
+
option used to be disabled by default on Windows, but now it is enabled by
|
1032
|
+
default everywhere. If the Vim Ruby interface is available, this option is
|
1033
|
+
mostly ignored, as spawning a new process is generally the bottleneck for most
|
1034
|
+
expensive operations. Set this option to 0 if you experience painful delays
|
1035
|
+
when first editing a file from a Rails application.
|
1036
|
+
|
1037
|
+
*rails-screen* *g:rails_gnu_screen* >
|
1038
|
+
let g:rails_gnu_screen=1
|
1039
|
+
Use GNU Screen (if it is running) to launch |:Rconsole| and |:Rserver| in the
|
1040
|
+
background. Enabled by default.
|
1041
|
+
|
1042
|
+
*g:rails_history_size* >
|
1043
|
+
let g:rails_history_size=5
|
1044
|
+
Number of projects to remember. Set to 0 to disable. See |rails-menu| for
|
1045
|
+
information on retaining these projects across a restart.
|
1046
|
+
|
1047
|
+
*g:rails_mappings* >
|
1048
|
+
let g:rails_mappings=1
|
1049
|
+
Enables a few mappings (mostly for |rails-navigation|). Enabled by default.
|
1050
|
+
|
1051
|
+
*g:rails_modelines* >
|
1052
|
+
let g:rails_modelines=1
|
1053
|
+
Enable modelines like the following: >
|
1054
|
+
# Rset task=db:schema:load
|
1055
|
+
Modelines set buffer-local options using the :Rset command.
|
1056
|
+
Also enables method specific modelines (note the case difference): >
|
1057
|
+
def show
|
1058
|
+
# rset preview=blog/show/1
|
1059
|
+
Modelines are deprecated and disabled by default.
|
1060
|
+
|
1061
|
+
*g:rails_menu* >
|
1062
|
+
let g:rails_menu=1
|
1063
|
+
When 2, a Rails menu is created. When 1, this menu is a submenu under the
|
1064
|
+
Plugin menu. The default is 1.
|
1065
|
+
|
1066
|
+
*g:rails_url* >
|
1067
|
+
let g:rails_url='http://localhost:3000/'
|
1068
|
+
Used for the |:Rpreview| command. Default is as shown above. Overridden by
|
1069
|
+
b:rails_url.
|
1070
|
+
|
1071
|
+
*g:rails_statusline* >
|
1072
|
+
let g:rails_statusline=1
|
1073
|
+
Give a clue in the statusline when this plugin is enabled. Enabled by
|
1074
|
+
default.
|
1075
|
+
|
1076
|
+
*g:rails_subversion* >
|
1077
|
+
let g:rails_subversion=1
|
1078
|
+
Automatically add/remove files to the subversion repository for commands like
|
1079
|
+
|:Rgenerate| and |:Rdestroy| (but not |:Rscript|). Ignored when the
|
1080
|
+
application is not part of a subversion repository. Deprecated and disabled
|
1081
|
+
by default.
|
1082
|
+
|
1083
|
+
*g:rails_syntax* >
|
1084
|
+
let g:rails_syntax=1
|
1085
|
+
When enabled, this tweaks the syntax highlighting to be more Rails friendly.
|
1086
|
+
Enabled by default. See |rails-syntax|.
|
1087
|
+
|
1088
|
+
*rails-tabs* *g:rails_tabstop* >
|
1089
|
+
let g:rails_tabstop=4
|
1090
|
+
This option now requires the plugin railstab.vim from vim.org:
|
1091
|
+
http://www.vim.org/scripts/script.php?script_id=2253
|
1092
|
+
|
1093
|
+
If your goal is simply just override this plugin's settings and use your own
|
1094
|
+
custom 'shiftwidth', adjust things manually in an autocommand: >
|
1095
|
+
autocmd User Rails set sw=4 sts=4 noet
|
1096
|
+
This is highly discouraged: don't fight Rails.
|
1097
|
+
|
1098
|
+
==============================================================================
|
1099
|
+
ABOUT *rails-about* *rails-plugin-author*
|
1100
|
+
|
1101
|
+
This plugin was written by Tim Pope. Email him at <vimNOSPAM@tpope.info>. He
|
1102
|
+
can also be found on Freenode's IRC network, hanging out in #rubyonrails and
|
1103
|
+
#vim as tpope.
|
1104
|
+
|
1105
|
+
The official homepage is
|
1106
|
+
http://rails.vim.tpope.net
|
1107
|
+
The latest stable version can be found at
|
1108
|
+
http://www.vim.org/scripts/script.php?script_id=1567
|
1109
|
+
In Vim 7, you can keep up to date with |GetLatestVimScripts|.
|
1110
|
+
|
1111
|
+
The very latest development versions can be retrieved from Git:
|
1112
|
+
http://github.com/tpope/vim-rails
|
1113
|
+
git clone git://github.com/tpope/vim-rails.git
|
1114
|
+
|
1115
|
+
Feedback is highly desired on this plugin. Please send all comments,
|
1116
|
+
complaints, and compliments to the author. No bug is too small to report.
|
1117
|
+
|
1118
|
+
*rails-license*
|
1119
|
+
This plugin is distributable under the same terms as Vim itself. See
|
1120
|
+
|license|. No warranties, expressed or implied.
|
1121
|
+
|
1122
|
+
==============================================================================
|
1123
|
+
vim:tw=78:ts=8:ft=help:norl:
|