Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vim go to ruby class declaration

I want to follow from

class ApplicationController < ActionController::Base

to

/home/slavik/.rvm/gems/ruby-1.9.2-p290/gems/actionpack-3.1.0.rc6/lib/action_controller/base.rb

and look to commented reference of possible usage this class

like image 333
Vyacheslav Loginov Avatar asked Jul 30 '26 09:07

Vyacheslav Loginov


2 Answers

Yes, there is at least one way. You can use exuberant ctags in combination with the tags option of Vim. Pratically, you have to execute ctags in the /home/slavik/.rvm/gems/ruby-1.9.2-p290/gems/ like :

ctags -R tags

See ctags --help if you want to dig into tags customization. Then you have to add this file to your tags path in vim. Using something like the following:

:set tag+=/home/slavik/.rvm/gems/ruby-1.9.2-p290/gems/tags

In order to understand how powerful this vim features is take a look at Browsing_programs_with_tags.

like image 71
lucapette Avatar answered Aug 02 '26 15:08

lucapette


There are couple of issues with ctags which has pretty old and ugly parser:

  • Ctags doesn't deal with: module A::B
  • Ctags doesn't tag (at least some of) the operator methods like ==
  • Ctags doesn't support qualified tags, -type=+
  • Ctags doesn't output tags for constants or attributes.

I would recommend better project ripper-tags based on official Ruby parser called Ripper which is included in Ruby. It is fast and accurate: https://github.com/tmm1/ripper-tags

You can also install gem-ripper-tags to have tags files automatically generated after gem installation: https://github.com/lzap/gem-ripper-tags

Please note that these days, August 2013, there is a big refactoring of ripper-tags which can lead to change of command line options or gem-ripper-tags interface. If things are not working, update both gems in couple of days and read help screen to learn new options.

like image 40
lzap Avatar answered Aug 02 '26 15:08

lzap



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!