What method are vim users out there using to quickly access documentation for both ruby and rails (other than switching to the browser to use ruby-doc or railsapi?).
I was trying to adapt this script (http://vim.wikia.com/wiki/Online_documentation_for_word_under_cursor) to do the trick however it's only going to work if the cursor is over a class name and I'd like it to work with both class and met开发者_C百科hods.
Thanks.
Seems like you may have answered this yourself with that function, but there are a couple of existing Vim plugins that can access ri on-the-fly within Vim. I use PA_ruby_ri. You might also try ri-browser and ruby-menu, though I can't personally vouch for either of them.
Managed to modify the script in the OP to work with the slick http://railsapi.com (which also provides docs for ruby, rspec and more).
Added the below to my .vimrc, then using leader + d will load up the docs for the word the cursor is on:
" online documentation search
function! OnlineDoc()
if &ft =~ "ruby"
let s:urlTemplate = "http://railsapi.com/doc/rails-v2.3.8_ruby-v1.8/?q=%"
else
return
endif
let s:wordUnderCursor = expand("<cword>")
let s:url = substitute(s:urlTemplate, "%", s:wordUnderCursor, "g")
let s:cmd = "!open \"" . s:url . "\""
execute s:cmd
endfunction
map <silent> <leader>d :call OnlineDoc()<CR>
coreyward, please don't use this, ha.
This is an old post but for future googlers, I'd suggest 2 plugins:
- ri.vim: to bring up offline
ri
docs within Vim. - vim-ruby-doc: to bring up online rdoc.info, api.rubyonrails.org, or rspec relish docs in a browser.
BTW If you're looking for CSS, DOM, HTML, JavaScript, JQuery, or PHP documentation check out my lil plugin dochub.vim.
Install the cheat sheets gem and simply shell out to access a quick help text.
:! cheat cheat
Rob Conery over at Tekpub.com uses this gem in his rails videos and it is quite useful.
I usually use a browser to read online docs, because of hyperlinking. It makes it a lot easier to jump around between related pages.
Otherwise, I'll keep a terminal window open, for ri
and man
pages.
Also, inside vim, I'll open a separate tab and use that to view docs. That works pretty well because I don't have to shuffle splits.
The last two are old-school, but they work well.
If you're on a Mac, try dash.vim. Works for Rails and lots of other frameworks and languages as well.
精彩评论