vim/macvim: locate where a method/symbol is defined - ruby-on-rails

I'm using macvim/vim for most of my Ruby + Ruby on Rails development. Is there currently a way to jump to where a method was defined within a project, even if it's not in the same file as where it's being invoked? Either a language agnostic way or a Ruby/Rails specific way works.

I recommend using the ctags plugin, Bryan Liles put together a nice screencast on how to use it with rails development.
http://smartic.us/2009/04/05/using-ctags-in-vim/
From his page:
Not-so-complete cheat sheet:
^] – find a tag
^T – go backwards
:tags – show where you’ve been
:tag – go somewhere in your tag stack
:tselect or g] – show where something is referenced
^W-] – find a tag in a split window
You can also have a look at the vim help by running: help :tags
EDIT:
Here is a nice screencast on updating your tags file automatically http://smartic.us/2009/04/03/creating-ctags-with-git-hooks/

Related

Create custom ruby text transformations in Rubymine

I thought this would be something built in and easy to do in Rubymine but I haven't been able to find any references to it let alone possible answers. Maybe I am phrasing my searches all wrong? I want to create a simple ruby script that I can use to transform text in Rubymine. I have to do a lot of snake_case to titleize transformations in my writing of some rails forms. I wish I could highlight some text and right click -> Titleize and have it happen, but Rubymine only does upcase/downcase or snake_case/camelCase conversions. It seems like I should be able to write a simple script like:
require 'active_support'
gets some_string
some_string.titleize
and assign it to a menu item. Any ideas? Right now I open the terminal panel in Rubymine where I have rails c running and copy/paste -> .titleize -> copy/paste.
I don't believe there is a way to do this right now using ruby. The use of RubyMine macros is quite limited, think you could take a look to some simple plugin like CamelCase take it apart and see what they are doing, but that would force you to use Java I guess.
However if you are interested only in the specific case of
snake_case > Snakecase
For that you could install the CamelCase and record a macro and assign it to a any shortcut you like , the macro itself would do this
ALT+SHIFT+U > SnakeCase
CTRL+SHIFT+U > snakecase
ALT+SHIFT+U > Snakecase
Hope that helps.

How to get the rails.vim-command :Rview working with .js.erb-views?

I want Rview to jump to .js.erb-views as well.
It always says "Can't find file "app/views/examples/foo".
The help says:
rails-template-types
Commands like :Rview use a hardwired list of
extensions (erb, rjs, etc.) when searching for files. In order to
facilitate working with non-standard template types, several popular
extensions are featured in this list, including haml, liquid, and mab
(markaby). These extensions will disappear once a related
configuration option is added to rails.vim.
Since the view ends with .erb, i would suggest it should work.
Any Ideas?
This is strange, I just checked in my vim and it works fine. I use Janus, but I think that the standard vim + rails.vim should work well.
Maybe you need to update rails.vim?
And you can tell the sequence of your actions: the current file, typed commands, etc.

How can I syntax check (not render) a Rails 3 ERB template file?

I'm trying to have a git pre-commit hook perform a syntax check on all Ruby code; there is one on GitHub at https://github.com/cypher/git-ruby-syntax-check.
It attempts to check .erb files by erb -x to translate them into Ruby code and then passes the output to ruby -c for syntax checking. Unfortunately, Rails 3 introduced a custom ERB parser that is incompatible with Ruby's standard ERB, and so the pre-commit hook is finding errors where there are none.
Is there some equivalent to erb -x that will output Ruby code from a Rails 3 ERB file?
I have not dug much into either of these but you might try rails-erb-check (Git project) or this blog entry. I agree with shingara but the Blog Post describes a situation where this is useful and I wonder if you are in a similar position:
Diaspora is pretty fluid right now. This means we are have some green
tests, some missing tests, and other tests that check intent (not
implementation). In an ideal world, I suppose test cases would cover
all of our bases...
Until then, I've added a new task to my fork, check_syntax:all. This
breaks down further to the subtasks check_syntax:erb,
check_syntax:haml, check_syntax:haml_ruby, check_syntax:sass, and
check_syntax:yaml.
If you get an "argument list too long error" for rails-erb-check , you can try rails-erb-lint which scans your current views folder.

easy shortcut for <%= in vim (for rails apps)

I type <%= often enough in rails that I want to find a shortcut for it. I am looking for a VIM solution (I specifically use macVim)
I know I can map it to keys or create my own snippetMate.vim snippet but I'm wondering if there's a generally accepted way of doing this.
Vim has abbreviations functionality out of the box. Enter:
:ab < <%=
then when you type < followed by <SPACE> in insert mode it will expand to <%=.
See :help :ab for more information.
tpope has created a plugin that you might find useful called Ragtag
It comes bundled with many mappings, but specifically the following
Mapping Changed to (cursor = ^) ~
<C-X>= foo<%= ^ %>
tpope has a great collection of plugins:
rails.vim
surround
pathogen
endwise
unimpaired
If you are doing any rails development I would highly suggest you look into rails.vim
The snippet way seems the best way to do that.
You can also add the following to your .vimrc:
imap <c-b> <%=
This adds the <%= whenever you type Control b.

Easily create a Ruby on Rails partial from an existing block of markup using vim

Is there currently a plugin that you ruby on rails developers that are also using macvim/gvim/vim that allows you to take a quick block of code and create a partial from it? I know that TextMate does this, figured someone has ported it by now to vim also.
You want Tim Pope's rails.vim plugin:
http://rails.vim.tpope.net/
It provides an :Rextract command that pulls a range of lines into a partial. Here's a very short demo of it in action:
http://rails.vim.tpope.net/images/rpartial.gif
(The :Rpartial command in the demo is an alias for :Rextract.)
The plugin provides dozens of other features, too, and many people consider it a must-have for Rails development in Vim.
It works in vim with vim-rails plugin.
Select in visual mode code which you need to send to partial
Press key : and you will see :'<,'>
Complete command to :'<,'>Rextract partial_name where partial_name will your partial's file name. You can set folder for partial, for example :'<,'>Rextract shared/menu
Press Enter and enjoy.
rails.vim can do this. From the features summary:
:Rextract file replaces the desired
range (ideally selected in visual line
mode) with render :partial => 'file',
which is automatically created with
your content. The #file instance
variable is replaced with the file
local variable.

Resources