How does one navigate Ruby methods in VIM? How does one navigate Ruby methods in VIM? ruby ruby

How does one navigate Ruby methods in VIM?


:help ]m

I think it requires vim-ruby for ruby support.


you'll want a feature called ctags

see exuberant ctags, it works for many languages included Ruby and is v simple to use.

from VIM :help ctags

ctags will create an index of all identifiers in a source tree. You can then use the tag commands to navigate around your source tree. see :help tag-commands. The easiest is to place the cursor over a keyword and press CTRL-]. To get back to where you came from press CTRL-T

Beyond this you might want to look at this page which documents how to use VIM as a more full featured Ruby IDE: Using Vim as a Complete Ruby On Rails IDE


Best solution for Vim: use ctags. Read Vim documentation about how to navigate in TAGS files, also install plugin like CtrlP which allows you to visually browse tags.

Warning: Exuberant ctags does not work well with Ruby, the parser is not in good condition and it has not been changed 4 years now.

  • 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.

Unfortunately all the others (I found 2) Ruby ctags generators are either outdated (no Ruby 1.9+ support) or very slow.

There is one solution tho. Ripper-ctags: https://github.com/tmm1/ripper-tags It is fast and it works as expected. It is based on Ruby 1.9+ feature called "Ripper" which allows us to build on top of (fast) Ruby original parser. It is the most accurate ctags generator today.

Ripper CLI options are almost identical to ctags, so if you already know ctags, you will find ripper-tags easy to learn. It's as easy as:

ripper-tags -R .

This creates TAGS file which vim automatically reads by default (must be the directory where you open your vim instance in, or manually change path setting in vim if you start it in a different directory - more in the Vim manual).

If you like this, you can go step further and install my project which automatically creates TAGS for all the gems you install: https://github.com/lzap/gem-ripper-tags

Usage is very simple (note again, only Ruby 1.9+):

gem install gem-ripper-tags

Then generate tags for all already installed gems:

gem ripper_tags

Anytime you install a gem now, tags will be automatically created.

gem instal some_gem ...

I go one additional step further - I have a git template which is regenerating my project TAGS after every git pull or merge automatically (using ripper-tags):

https://github.com/lzap/bin-public/blob/master/git-hooks-reinstall

Note you will need directory files/git_template as well from the very same git repository.

I hope this is good starting point for navigating in Ruby codebases :-)