Giter VIP home page Giter VIP logo

vim-rails's Introduction

rails.vim

This is a massive (in a good way) Vim plugin for editing Ruby on Rails applications.

  • Easy navigation of the Rails directory structure. gf considers context and knows about partials, fixtures, and much more. There are two commands, :A (alternate) and :R (related) for easy jumping between files, including favorites like model to schema, template to helper, and controller to functional test. Commands like :Emodel, :Eview, :Econtroller, are provided to :edit files by type, along with S, V, and T variants for :split, :vsplit, and :tabedit. Throw a bang on the end (:Emodel foo!) to automatically create the file with the standard boilerplate if it doesn't exist. :help rails-navigation

  • Enhanced syntax highlighting. From has_and_belongs_to_many to distance_of_time_in_words, it's here.

  • Interface to the rails command. Generally, use :Rails console to call rails console. Many commands have wrappers with additional features: :Generate controller Blog generates a blog controller and loads the generated files into the quickfix list, and :Runner wraps rails runner and doubles as a direct test runner. :help rails-exec

  • Default task runner. Use :Rails (with no arguments) to run the current test, spec, or feature. Use :.Rails to do a focused run of just the method, example, or scenario on the current line. :Rails can also run arbitrary migrations, load individual fixtures, and more. :help rails-default-task

  • Partial and concern extraction. In a view, :Extract {file} replaces the desired range (typically selected in visual line mode) with render '{file}', which is automatically created with your content. In a model or controller, a concern is created, with the appropriate include declaration left behind. :help rails-:Extract

  • Fully customizable. Define "projections" at the global, app, or gem level to define navigation commands and override the alternate file, default rake task, syntax highlighting, and more. :help rails-projections.

  • Integration with other plugins. If dispatch.vim is installed, :Rails and other command wrappers will use it for asynchronous execution. Users of dadbod.vim and dbext get easy access to their application's database. Users of abolish.vim get pluralize and tableize coercions, and users of bundler.vim get a smattering of features. :help rails-integration

Installation

If you don't have a preferred installation method, I recommend installing pathogen.vim, and then simply copy and paste:

cd ~/.vim/bundle
git clone https://github.com/tpope/vim-rails.git
vim -u NONE -c "helptags vim-rails/doc" -c q

While not strictly necessary, bundler.vim and dispatch.vim are highly recommended.

FAQ

I installed the plugin and started Vim. Why does only the :Rails command exist?

This plugin cares about the current file, not the current working directory. Edit a file from a Rails application.

I opened a new tab. Why does only the :Rails command exist?

This plugin cares about the current file, not the current working directory. Edit a file from a Rails application. You can use :AT and the :T family of commands to open a new tab and edit a file at the same time.

Can I use rails.vim to edit Rails engines?

It's not supported, but if you touch config/environment.rb in the root of the engine, things should mostly work.

Can I use rails.vim to edit other Ruby projects?

I wrote rake.vim for exactly that purpose. It activates for any project with a Rakefile that's not a Rails application.

What Rails versions are supported?

All of them, although you may notice a few minor breakages if you dip below 3.0. A few features like syntax highlighting tend to reflect the latest version only.

Didn't rails.vim used to handle indent settings?

It got yanked after increasing contention over JavaScript. Check out sleuth.vim.

Self-Promotion

Like rails.vim? Follow the repository on GitHub and vote for it on vim.org. And if you're feeling especially charitable, follow tpope on Twitter and GitHub.

License

Copyright (c) Tim Pope. Distributed under the same terms as Vim itself. See :help license.

vim-rails's People

Contributors

a2ikm avatar aripollak avatar cbartlett avatar chocoby avatar dasch avatar eljojo avatar francocatena avatar glittershark avatar graywh avatar jasoncodes avatar jbranchaud avatar jweslley avatar kalys avatar latortuga avatar lingceng avatar lucascaton avatar mwilden avatar mwunsch avatar ngauthier avatar npezza93 avatar npupko avatar rafe avatar rsludge avatar rtlechow avatar scrooloose avatar tonkpils avatar tpope avatar tylerrick avatar workgena avatar xrav3nz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

vim-rails's Issues

gf on render

gf works on

render :partial => 'blah'

, but not on

render 'blah'

when 'blah' is a partial.

[feature request] Extract selection to module, similar to extract partial

It would be nice if :Rextract could extract code to an external module when inside a class.

Something like this:

:'< ,'>Rextract module_name

Could generate a module_name.rb file declaring a ModuleName module containing the selected code. What I can't figure out yet is the best way to specify the file path.

Well, just an idea :)

Thanks for this awesome Vim plugin!

tiny patch: open rdoc without hanging vim

This is a fantastic piece of work. I would like it, though, if it were possible to call :Rdoc without locking up gvim, as seems to happen. The fix, at least for Unix, is just add the '&' at

1337 command -bar -nargs=1 OpenURL :!sensible-browser &

in autoload/rails.vim. Thanks.

Option to keep sts, sw and expandtab values unchanged

I don't like the way rails.vim sets tab spacing options to same value (2 spaces) for all files in rails project. sts=4 sw=4 noexpandtab is my preferred option for javascript files. It would be nice to have an option to disable setting these values for some filetypes or altogether. For example a quick hack to disable it via global configuration variable.

--- rails.vim.orig      2010-08-04 12:28:03.000000000 +0300
+++ rails.vim   2010-08-04 12:36:35.000000000 +0300
@@ -4619,9 +4619,11 @@
   call self.setvar('&suffixesadd', ".rb,.".s:gsub(s:view_types,',',',.').",.css,.js,.yml,.csv,.rake,.sql,.html,.xml")
   let ft = self.getvar('&filetype')
   if ft =~ '^\%(e\=ruby\|[yh]aml\|javascript\|css\|s[ac]ss\|lesscss\)$'
-    call self.setvar('&shiftwidth',2)
-    call self.setvar('&softtabstop',2)
-    call self.setvar('&expandtab',1)
+    if !exists("g:rails_keep_tabstops") || !g:rails_keep_tabstops
+      call self.setvar('&shiftwidth',2)
+      call self.setvar('&softtabstop',2)
+      call self.setvar('&expandtab',1)
+    endif
     if exists('+completefunc') && self.getvar('&completefunc') == ''
       call self.setvar('&completefunc','syntaxcomplete#Complete')
     endif

:Rails gives errors with rails3

I don't know if rails3 is supported yet, but I get errors

:!rails foo
/Users/daniel/.rvm/gems/ruby-1.9.1-p378/gems/railties-3.0.0.beta2/lib/rails/generators.rb:6:in require': no such file to load -- active_support/core_ext/object/singleton_class (LoadError) from /Users/daniel/.rvm/gems/ruby-1.9.1-p378/gems/railties-3.0.0.beta2/lib/rails/generators.rb:6:in<top (required)>'
from /Users/daniel/.rvm/gems/ruby-1.9.1-p378/gems/railties-3.0.0.beta2/lib/rails/commands/application.rb:10:in require' from /Users/daniel/.rvm/gems/ruby-1.9.1-p378/gems/railties-3.0.0.beta2/lib/rails/commands/application.rb:10:in<top (required)>'
from /Users/daniel/.rvm/gems/ruby-1.9.1-p378/gems/railties-3.0.0.beta2/bin/rails:30:in require' from /Users/daniel/.rvm/gems/ruby-1.9.1-p378/gems/railties-3.0.0.beta2/bin/rails:30:in<top (required)>'
from /Users/daniel/.rvm/gems/ruby-1.9.1-p378/bin/rails:19:in load' from /Users/daniel/.rvm/gems/ruby-1.9.1-p378/bin/rails:19:in

'

shell returned 1

Press ENTER or type command to continue

:R in a controller method

I'm not sure if this is the place to ask my question. I'm sorry if it isn't.

The help says that :R in a controller method brings up the view. When I do that it's bringing up the helper for me rather than the view. I was curious if this was happening for anyone else, or if it's my personal issue. :R from a view does bring me to the controller method, but not vice versa.

In looking at the code, I think it might be near line :2972.

I'm also curious if there's a recommended approach for customizing :R, :A behavior. Fork and customize?

Thanks!

":A" can not jump from the unittest test/unit to app/services

Hello,

I have a app/services/foo_bar.rb and test/unit/foo_bar_test.rb, I can jump from app/services/foo_bar.rb to unittest with :A, but I can't jump back from unittest with :A, it will give following warning information:

E345: Can't find file "app/models/sohu_service.rb" in path

interaction with vim sessions

When I use :mksession before quitting and then reload it (vim -S), rails.vim seems to forget how to properly search the project path (e.g. tab completion with :Rfind is broken, gf doesn't work).

On windows, path is constructed with forward slash, giving error message

On windows, when i try to access any rails application file i get the error " does not appear to be under the Rails path. Please contact rails.vim author". I tried to figure it out and it turns out that the "supposed path" is constructed with forward slashes as the "actual path" contains backslashes, which i believe is the cause of the error message.
Using Windows 7, gVim 7.2 with lucasprim/vimfiles

Ruler shows duplicate values

When Rails.vim is active (i.e. within a Rails project), VIM's default rulerformat setting is changed in such a way that what should be "20, 4" (line 20, character 4) shows up as "20, 4-4". I understand the usefulness of the dash: if "number of characters displayed" differs from "number of bytes in the text" then both "text column" and "screen column" values are shown. But why show both values when they are the same? Maybe this is intended behavior, but 99% of the time I see the same number on both sides of the dash which suggests that the common case should be optimized (i.e. switch back to default VIM rulerformat).

newbie having trouble getting anything to work; lots of E345 (can't find file), not opening in new tabs, not dumping into default file upon creation -- SOLVED! Kind of.

I'm still fairly new at vim in general and just started checking out rails.vim -- I like it a lot, but I'm having trouble getting it to work.

Most alarming to me is that the core functionality (in my mind so far), being able to jump between related files, is not working. It worked for a little while for me this morning, but suddenly stopped, both with a rails 3 and with a rails 2.3.8 project. For example, typing "[f" in a "Thing" model says "E345: Can't find file 'test/unit/thing_test.rb' in path"--but it does exist in the path! rails.vim is just failing to open it. When I type "]f", I get the same message about db/schema.rb, which obviously exists also. I find that alarming also because I doubt I'd ever personally consider db/schema.rb to be the file related to a model...

Also, I set "let g:rails_default_file='config/database.yml' " in my .vimrc file, but when I create a new project from within Vim, I do not end up in the database.yml, I just stay where I was. I need to manually switch into the new directory I created and open up database.yml. Not core functionality here, but everything seems to be broken.

Another thing I noted: I created a model called "Thing" while editing my database.yml, and rather than opening app/model/thing.rb in a new tab, it just replaced the file I was editing. I don't mind this a whole lot, but it could be quite inconvenient.


Ok, I just did a large troubleshooting of my .vimrc with this, and it appears these were the settings that were causing the problems (or at least the problems with switching between related files):

au BufWinLeave * mkview
au BufWinEnter * silent loadview

I was using these to remember folds that I set in files. If you know of a better way, that would be great!

rails_ctags_arguments default is wrong

According to the docs, the default option excludes JavaScript files whose filenames match *.*.js (attempting to exclude minified jQuery plugins). According to the code, it's set to exclude *.js. A fix: 48ed067

Cannot use Plugins->Rails commands on Windows

The path used by the command is using Linux conventions (see below script/console instead of script\console):

:!start ruby -C "C:\tmp\my_app" script/console

I also noticed that all commands will use Linux path separator instead of Windows. This will cause all commands to fail.

Is there an easy fix for this? Can I help?

Support for Gems

Would it possible to support gems as well? I can understand that considering the name of the plugin gems might be slightly outside its purview, but I really do miss having it there.

feature request

It would be nice if gf on controller action without template open empty template.

Rfind with model directories

In my models directory, I have this structure:

user.rb
user/validation.rb
user/states.rb

Now if I run Rfind user, I get the message 'user is a directory', and I have to reopen the previous file manually.

Syntax highlighting for regex and strings with /

The following will mess up the syntax highlighting: /this is #{"my re/gex"} test/

By "mess up" I mean that it thinks that the / between e and g is the end of the regular expression. Then it thinks the " after the x is the start of a new string.

I'm on version 4.2 of this plugin. I have Ubuntu 9.10.

$ gvim --version
VIM - Vi IMproved 7.2 (2008 Aug 9, compiled Sep 21 2009 11:22:21)
Included patches: 1-245
Compiled by [email protected]

Rails 3 omni completion error

i am using rails 3 on rvm and when i try to complete some word than i get error rails rquires ruby version 1.8.7 or 1.9.2 . i am running 1.9.2 using rvm but it don't detects installation (command ctrl+x ctrl+o) don't works

Plugin slows down vim

The rails.vim plugin causes gvim to be slow on my Ubuntu machine. Does not appear to affect console vim on the same machine or MacVim on my work machine. As soon as I disable the plugin (by removing it from my ~/vim/bundle directory and restarting vim), it goes back to the normal speed.

My specs:

  • Ubuntu Desktop 10.10 64bit
  • vim 7.3.32
  • rails.vim v4.3

Buffer opening raises error due to statusline

Hi Tim,

Using win7 x64, vim 7.3, vim.rails 4.3, ruby 1.8.7 and rails 3.0.3, I get the following error any time a relevant buffer is opened.

E121: Undefined variable: [Rails]
E15: Invalid expression: StatusLine()%{rails#statusline()}

I could trace the issue back to autoload/rails.vim line 3819, but I'm not familiar enough with the scripting language to debug. (In master, it seems to be the line 3838.)

If the bleeding edge is known to solve this issue, I'll be happy to upgrade.

So far everything else works perfectly, you put together a very nice plugin. Outstanding piece of work!

Thank you for your time.

lesscss and saas support

It would be nice if Rstylesheet match against several types of stylesheets: css, less and saas

Not an Editor Command error

I am a beginner to both vim and rails and I have been trying to use vim for rails project development.

So I ran "rake install" in the terminal to install rails.vim and everything seemed to be just fine.

But when I launched vim and try to use :Rails and other commands, vim always throws back a "Not an Editor Command" error. I was able to let :Rails! correctly shows the version (4.3) but just not the rest of the commands. Can anyone see where's the problem?

Thanks in advance

Integration with git-vim

Hi there,

vim-rails does not chdir into the rails root when opening a rails file, and therefore the helpers in git-vim fails (as it tries to do git-status etc. on ~). Could this be mitigated somehow?

Error detected while processing ruby.vim

Hi,

I installed vim, started installing rails.vim by copying files in vimfiles - after starting I am getting this error --

Error detected while processing C:\Program Files\Vim\vim73\ftplugin\ruby.vim:
line 76:
Encoding::ConverterNotFoundError: code converter not found (UTF-16LE to ASCII-8BIT)
line 93:
E121: Undefined variable: s:ruby_path
E15: Invalid expression: s:ruby_path

What may be the issue?

Thanks,
Sawan

Status line lost (fugitive)

I noticed that with both rails.vim and fugitive running I can't get the fugitive status line to work while rails is activated. I don't know how to have the two status lines play nice together. Also
let g:rails_statusline=0
doesn't seem to turn it off. How do you turn it off if you needed to?

[Feature] Repeat last rake task

In some cases you are fixing a bug by getting deeper and deeper into the code. If you are keep checking your fix with a test it is annoying to come back to the test file and run Rake command again.

I think it would be good to have ability to run Rake with previously used argument. Whether it was a spec, cucumber scenario or db:migrate.

:Rails and Rails3.beta4

Beta 4 rails projects are started with "rails new path/to/project", rather than the previous "rails path/to/project".

I am new to rails.vim, but it appears the :Rails command does not support this as of yet.

Declaritive test syntax

My favorite command is .Rake from within a test function. At some point, the default scaffold test code has changed from:

def test_should_do_something
  ...
end

to an exciting and trendy new style

test "should do something" do
  ...
end

And vim-rails is unable to detect the current test. I'm afraid I am completely lost as to how to provide a patch to this, I looked at the vim code but it just made my head hurt. Support for the old style uses self.last_method to get the test method name. In this case I guess something like self.last_block is needed.

For the record, given the above new declarative style syntax, TESTOPTS="-ntest_should_do_something" still works, so if there is a way to do self.last_block then the following conversion would be required with the result.

test "should do something" => test_should_do_something

Personally, I'm still using the old syntax and am quite happy to continue doing so, but I guess vim-rails should probably support the Rails defaults. Sorry again for the lack of a patch.

:Rake on feature file

When I'm on a cucumber feature file, ":Rake" does not appear to load step definitions.

[feature request] Navigation commands preview mode

It would be cool if in addition to currently supported navigation commands like Rmodel, RSmodel, etc. there will be the RSPmodel(Split preview) and RVPmodel(Vertical split preview) commands that will open new window but do not move cursor to opened window.

Rails 3 Support

Hello TIm,

Is there a release of vim-rails for rails3 planned?
Are there any patches which might help me use vim-rails for rails3?

thanks,
aakash

Requires "rails new" to create new project

To create a new project now requires "rails new some/path" as opposed to "rails some/path". Line 1015 of autoload/rails.vim needs to be changed to:

exe "!rails new".append.str

Thanks!

Load path error with vim sessions

hi, I encountered the same problem as described in Issue 7 (closed already) while saving vim's session with mks! and reloading it back with vim -S.

I found out that the problem lies in the saved "setlocal path=...." lines in the Session.vim file.

Because I'm using rvm, this line gets filled with, not only my current project dirs, but also all .rvm gem dirs, which is alot, i.e. more than 4096 chars. This leads to a truncated incorrect path string, not sure if this is a vim limit or bug, but I'm able to fix it by deleting or replacing all these "setlocal path=...." lines with a post-save vim script.

This method feels a bit hacky, can you suggest an alternative or maybe point me to the line where you set the buffer paths in your rails.vim script?

thanks, keep up this great plugin!

[Feature request] Support for workling workers

I'd like to be able to search :Rworker, and also have :Rfind automatically parse the app/workers (currently, I have to search type through from the root of the project to find my workers).

[Feature request] Running single spec under the cursor

If this feature is already there and I'm missing it please let me know. What I would like is a command like ':Rake single' or :Rsingletest to run the test the cursor is currently at. At the moment, I'm reduced to doing ':Rake <line_number>' which works fine except for manual step of checking which line I'm on.

Project detection on tabnew

When opening vim or mvim with no args in application root of any rails project, the plugin detects the project and all R commands are available. However, when opening a new tab though still in the app root, R commands are not available as if the project has not been detected. Opening a project file manually, :e config/routes.rb for example, will cause the R commands to be available.

The plugin seems to be loaded in the new tab but the project detection does not seem to be functioning on the opening of a new tab.

Rcommand errors

Whenever I open a Rails file:

Error detected while processing User Auto commands for "Rails":
E492: Not an editor command: Rcommand sass public/stylesheets/sass -glob=* -suff
ix=.sass -default=controller()
E492: Not an editor command: Rcommand api app/apis -glob=/* -suffix=a
pi.rb
E492: Not an editor command: Rcommand config config -glob=
._ -suffix= -
default=routes.rb
E492: Not an editor command: Rcommand environment config/environments -default=.
./environment
E492: Not an editor command: Rcommand initializer config/initializers -glob=.
-default=plugins.rb
E492: Not an editor command: Rcommand concern app/concerns -glob=
/*
E492: Not an editor command: Rcommand mailer app/mailers -glob=*/

This is in my .vimrc:

au User Rails Rcommand sass public/stylesheets/sass -glob=* -suffix=.sass -default=controller()
au User Rails Rcommand api app/apis -glob=/* -suffix=api.rb
au User Rails Rcommand config config -glob=
._ -suffix= -default=routes.rb
au User Rails Rcommand environment config/environments -default=../environment
au User Rails Rcommand initializer config/initializers -glob=. -default=plugins.rb
au User Rails Rcommand concern app/concerns -glob=
/*
au User Rails Rcommand mailer app/mailers -glob=*/

This used to work, what's changed?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.