• Stars
    star
    113
  • Rank 310,115 (Top 7 %)
  • Language
    Ruby
  • License
    MIT License
  • Created over 12 years ago
  • Updated 8 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

browse ri documentation from Vim

ri plugin for Vim

This plugin lets you search and navigate Ruby library and gem documentation inside Vim.

screenshot

Advantages over the venerable ri command-line tool:

  • write code and browse pertinent documentation in adjacent Vim windows
  • search with autocompletion help
  • hyperlinking lets you jump from definition to definition
  • run back and forth through your jump history with CTRL-o and CTRL-i
  • jump directly to gem READMEs and into the gem source directories
  • directly open corresponding HTML-formatted rdoc documentation

Prerequisites

  • Ruby 1.9.2 or higher
  • Vim 7.3 (will not work correctly on 7.2)
  • rdoc 3.8 or higher

Install

Copy the contents of plugin/ into your .vim/plugin directory.

Commands

For all the commands below, the mapleader is assumed to be ,. If it is \ or something else for your setup, use that instead.

Invoking the plugin

  • ,r opens the search/autocomplete window, and will use a horizontal split to display matching documentation
  • ,R opens the search/autocomplete window, and will use a vertical split to display matching documentatoin
  • ,K opens the search/autocomplete window and prefills it with the keyword under the cursor
  • K is automatically remapped to use ri.vim if the current buffer is a *.rb file

If these mappings clash or you don't like them, you can override some of them. See Changing keymappings below.

Using the search/autocomplete window

With the search/autocomplete window open, start typing the name of the class, module, or method you want to lookup.

Press TAB to start autocompletion.

If you've started typing a name starting with a capital letter, you'll see autocompletion suggestions for matching classes and modules. If you're looking for a namespace-nested module or class, you can autocomplete the first namespace, type : and then press TAB again to autocomplete the next inner namespace.

screenshot

If you've started typing a name starting with a lower case letter or a symbol that is valid in Ruby method names (i.e., /^[=*\/&|%^\[<>]/), ri.vim will suggest matching methods from different classes and modules.

screenshot

Use the standard Vim autocompletion commands to move up and down the match list.

  • CTRL-p and CTRL-n let you navigate the drop-down matches. Press ENTER to select one.
  • CTRL-e closes the match list and lets you continue typing
  • CTRL-u: when the match list is active, cycles forward through the match list and what you've typed so far; when the match list is inactive, erases what you've typed.
  • both TAB and CTRL-x CTRL-u reactivate autocompletion if it's gone away
  • CTRL-y selects the highlighted match without triggering ENTER

When you're searching for a class or module (but not yet for method searches), you will sometimes see a little number in parentheses to the right of a match. This is a rough indicator of how much actual documentation there is to see for that class or module. It actually represents how many "parts" of the generated documentation have a "comment" associated with them. (Don't ask me what the definition of a "part" is; it's just something the RDoc::RI codebase knows about.) Please note that the relationship between the number of comment-parts and the length of the documentation is not exactly linear. But it's still a useful filter for knowing which documentation pages are worth looking up.

The documentation window

  • ,,r invokes the class/module method autocompletion window
  • - goes up from a method page to the page of the parent class or module
  • CTRL-o and CTRL-i jump you back and forward through the documentation pages you've visited

When you find a matching method or class or module and press ENTER, you should see the ri documentation, with a light touch of color-highlighting, displayed in a Vim window.

screenshot

You can move the cursor to any valid Ruby method or class/module name on this page (including the class and instance methods at the bottom) and press ENTER to jump to the documentation.

You can also find a method on any class or module you're looking at the documentation for by pressing ,,r. This brings up the class/module method autocompletion window:

screenshot

Here you can just start typing the method name (you don't need to indicate whether it is a class or instance method) and press TAB. Then the match list should narrow down your choices quickly. Again, the numbers here are a very rough indicator of how much documentation there is to see for that method.

Let's look at #encode:

screenshot

When you are looking at the documentation for an instance or class method, you can still use ,,r to browse and jump to other methods on that same class or module.

You can also use - to jump up the hierarchy to the page for the String class. If you were in a nested class, e.g. File::Stat, you could also jump up to File with -.

Alternatively, you can use the standard Vim command CTRL-o to jump back to where you were before you jumped to this page. CTRL-i takes you back forward.

Gem READMEs and HTML RDocs

  • ,g takes you to the README of the gem, if you're looking at documentation for a gem
  • ,h opens the HTML RDoc version of the gem documentation you are looking at

If you are looking at documentation for a Gem, you can see the README for that gem (assuming it exists and is called README.*) by pressing ,g.

If you've generated the HTML RDoc documentation for this Gem, you can open it in a web browser by pressing ,h.

If you're looking at a gem's README, you can change the local working directory to the gem root directory by using the vim command :lcd %:h.

How to generate ri documentation

ri.vim won't work very well unless you have generated ri documentation for your Ruby built-in library, standard library, and your installed Ruby gems.

Please consult other reference sources for instructions specific to your particular setup.

I'll try to cover some common cases:

If you use RVM, run this to install ri documentation for the built-in and standard library of your active Ruby installation:

rvm docs generate-ri

You can check if this worked by running a command like ri Enumerable or ri IO on the command line.

To generate ri documentation for your gems, use these commands:

# for global gems
gem list | tr -d '(,)' | awk '{print $1, "--version", $2}' | xargs -n3 gem rdoc --ri --no-rdoc

# for bundled gems
bundle list | tr -d '*(,)' | awk '{print $1, "--version", $2}' | xargs -n3 gem rdoc --ri --no-rdoc

If you like using ri.vim, you may want to remove --no-ri if you added that to your .gemrc. This will make sure that the gem install command automatically generates ri documentation.

Changing keymappings

You can change the keymappings for invoking ri.vim by appending something like this to your .vimrc:

nnoremap  ,ri :call ri#OpenSearchPrompt(0)<cr> " horizontal split
nnoremap  ,RI :call ri#OpenSearchPrompt(1)<cr> " vertical split
nnoremap  ,RK :call ri#LookupNameUnderCursor()<cr> " keyword lookup

Alternatively you can also disable the default plugin mappings to set your own:

let g:ri_no_mappings=1

Maintainers

Acknowledgements

Thanks to Eric Hodel for developing the ri and rdoc infrastructure that ri.vim builds on. ri.vim adds just a little piece to that very useful codebase.

Thank you to Suraj Kurapati for the tip on how to generate ri documention for installed gems.

Bug reports and feature requests

Please submit them here:

About the developer

My name is Daniel Choi. I specialize in Ruby, Rails, MySQL, PostgreSQL, and iOS development. I am based in Cambridge, Massachusetts, USA.

License

MIT

More Repositories

1

vmail

a vim interface for gmail
Ruby
781
star
2

kindlefodder

Bring web docs to the Kindle
Ruby
366
star
3

herbalizer

Convert HAML to ERB
Haskell
114
star
4

fredit

Let collaborators edit your Rails front-end through the web browser
JavaScript
96
star
5

soywiki

A wiki engine built on top of Vim and Git
Vim Script
87
star
6

kindlerb

Kindle periodical format ebook generation tool
Ruby
79
star
7

vitunes

Control iTunes from Vim
Objective-C
68
star
8

virb

Interactive Vim mode for IRB, Rails console, and PRY
Ruby
56
star
9

openmbta

An iPhone app and data API for Boston MBTA schedules and other information
Objective-C
53
star
10

gitfinger

finger GitHub users
Ruby
34
star
11

jsontsv

Convert JSON to TSV / CSV / DSV
Haskell
28
star
12

boston-rubyists

Monitor the Boston Ruby world
JavaScript
23
star
13

ngrender

Pure server-side rendering of AngularJS templates
Haskell
23
star
14

openmbta2

rewrite of OpenMBTA
Ruby
22
star
15

twail

tail -f your Twitter
Ruby
21
star
16

vnews

A Vim-based newsfeed reader
Ruby
19
star
17

elinks.vim

Integrate elinks and vim
Vim Script
16
star
18

ri_vim

Browse Ruby documentation inside Vim
Ruby
15
star
19

firelinks

Sync elinks with Firefox
Ruby
10
star
20

twim

Post to Twitter from Vim
Ruby
10
star
21

hulu_automuter

Automute Hulu commericals
Ruby
10
star
22

goog

Search Google from the command line
Ruby
9
star
23

poddb_client

Podcatching from the command line and Vim
Ruby
8
star
24

docrails_kindle

Read the Rails Guides on your Kindle
Ruby
8
star
25

rb_nav

Navigate your Ruby project
Ruby
7
star
26

practicing-ruby-kindle

Kindle screenshots and sample of Greg Brown's Practicing Ruby series
6
star
27

hush

Mute Hulu commercials automatically on OS X
Ruby
6
star
28

itunes-command

Search and play iTunes tracks from the command line
Ruby
6
star
29

rails31nav.vim

simple way to traverse related rails 3.1 files
Vim Script
6
star
30

ruby_bashrockets.vim

Converts and unconverts hashrocket notation
Vim Script
5
star
31

mustache-haskell

mustache implementation in Haskell
Haskell
5
star
32

boston-ruby

Track BostonRB activity from the command line
Ruby
5
star
33

table

Format TSV, CSV, DSV into pretty plain text table
Haskell
5
star
34

ask_stack

Post questions to Stack Overflow from the command line
Ruby
5
star
35

gmail_archiver

Archive your gmail to PostgreSQL
Ruby
4
star
36

traderjoes-ipad

Objective-C
4
star
37

open_events

love your city
Ruby
4
star
38

todo.rb

a simple todo app
Shell
4
star
39

vimscript

Vim Script
3
star
40

startbrick

Make `rails s` open your browser when it's ready
Ruby
3
star
41

feed_yamlizer

another feed parser and converter
Ruby
3
star
42

mbta-subway-realtime-json

Converts MBTA real-time subway data into a JSON feed
Ruby
3
star
43

korea-stuff

My notes on Korean politics and history
2
star
44

boston-weather-service

A Sinatra proxy for boston.com weather
Ruby
2
star
45

http-service

Ruby
2
star
46

haskell-exercises

Some Haskell exercises
Haskell
2
star
47

eris

a system for planet style aggregation
JavaScript
2
star
48

tsvsql

Template TSV into SQL templates
Haskell
2
star
49

teaching-example

Rails 3 teaching example
Ruby
2
star
50

feed-engine

open source feed crawler service
2
star
51

listenlog-backend

Backend Rails app for projectvrm's listenlog project
JavaScript
2
star
52

any2html

Open markdown, textile, etc. formatted files in browser
Ruby
2
star
53

docs_on_kindle

I've been renamed to kindlefodder
1
star
54

traderjoes

Trader Joe's demo
JavaScript
1
star
55

test1

test1
Ruby
1
star
56

pager_mode.vim

toggle on and off less-style paging key-bindings in Vim
Vim Script
1
star
57

HsOpenSSL

Fork of HsOpenSSL that removes preprocessor macros causing build trouble on OS X
Haskell
1
star
58

hdbc-aeson

HDBC to Aeson adapter
Haskell
1
star
59

cocoa-doc

Ruby
1
star
60

gtfs-realtime

Haskell GTFS realtime
Haskell
1
star
61

tracker

Ruby
1
star
62

snap-blaze-digestive

Example code for Snap + digestive functors + blaze-html
Haskell
1
star
63

feedbase-old

feed aggregator base
Ruby
1
star
64

export-firefox-bookmarks

Ruby
1
star
65

HaskellNet

fork of HaskellNet library (ghc 7.4.1 compatible)
Haskell
1
star
66

eris-feeds

feed service for eris
Ruby
1
star
67

collection-json.hs

Haskell support for Collection+JSON
Haskell
1
star
68

vimrc

my .vimrc
Vim Script
1
star
69

docsrails-ipad

1
star
70

openmbta-ios

OpenMBTA ios clients
Objective-C
1
star
71

transparent

Haskell
1
star
72

otp-boston

open trip planner experiments for boston
1
star
73

haskell-examples

Haskell
1
star
74

guestlistapp

Stitch together guest list for a guestlistapp.com event
Ruby
1
star
75

twitter_monit

Monit your twitter from command line
1
star
76

min_mail

minimal mail client
Ruby
1
star
77

cocoa_tools

Some tools for writing Cocoa with Vim etc.
JavaScript
1
star
78

project-webpages

Webpage generator for my software projects
JavaScript
1
star
79

kajametro-ios

ios client for kajametro
Objective-C
1
star
80

boston-stitch

Stitch Boston.com galleries together (and avoid next button click fatigue)
Ruby
1
star
81

boston-music-planet

JavaScript
1
star
82

wikipedia-postgres

Ruby
1
star