GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — VimRubySupport VimRubySupport
Fladson Gomes edited this page
If you install Vim 7.x, the following Ruby support is enabled out of the box:
These files are maintained by @segfault, @dkearns, @tpope, @AndrewRadev, and @now. The purpose of this article is to describe what these features are, how they work, and how you can add other Ruby features. The target readership is those who use Ruby and Vim, but are not sure how to get the most out of the combination. When you install Vim 7.3 (please don’t use 6.x if you can help it!), the following important files are created (
Since Vim 6.x, a lot of configuration and extensions have been placed in plugins. For instance, from VimOnline you can download plugins for a calendar or tetris. These are global plugins. The files we are concerned with are filetype-specific plugins. The notion of filetype is central to Vim. When you load a file, Vim decides (based on either the filename extension or the file contents) the type of file you are editing. It then loads the specific runtime files for that filetype, in order to highlight it, indent it, and apply whatever other settings are deemed appropriate for files of that type. Files with either a filename extension of The filetype plugin files (ftplugin/*) are a place for miscellaneous configuration when editing Ruby and eRuby code: mappings, options, matchit configuration etc. See The syntax files contain instructions for Vim to highlight Ruby and eRuby code. See The indent files contain instructions for Vim to automatically indent Ruby and eRuby code. The compiler plugins contain instructions which allow Vim to run the specified source file with an appropriate executable, parse any errors, and jump to the corresponding error location if required.
To set a compiler, you can put the following line in your own ftplugin extension (for example, compiler ruby If you prefer to set it from your autocmd FileType ruby compiler ruby The omni completion function (autoload/rubycomplete.vim) file offers context sensitive (IntelliSense-like) completion similar to that available in irb. NOTE: This functionality is new for Vim 7 and requires a version of Vim compiled with the Ruby interface – see IMPORTANT: There is a bug in the Ruby interface for Vim 7.3 on Windows that can cause Vim to crash. This was fixed in version 7.3.088. To activate the completion menu type See While these files are included as part of the standard Vim distribution they tend to be updated more frequently than Vim itself. To install the latest version, your favorite method works. Here are some options. Install pathogen.vim, then copy and paste: git clone git://github.com/vim-ruby/vim-ruby.git ~/.vim/bundle/vim-ruby Install Vundle, then add the following to your vimrc: Plugin 'vim-ruby/vim-ruby' Download an archive and extract the relevant files to Unfortunately, although Vim has all this power, it is not enabled by default, primarily for “backward compatibility”, I suppose. So make sure these lines are contained within your
You should verify that your installation of vim-ruby is correct. A simple way to do this in Vim 7, which will test that the syntax, filetype, indent and omni completion scripts are working properly, is to: 1. Open a new Ruby source file. This file should have either a filename extension of ‘.rb’ or the appropriate shebang line (eg. 2. Edit the buffer and insert the string:
The fragment should be highlighted and automatically indented as you type. 3. Add the ‘dot’ operator after the string and while in insert mode type CTRL-N and CTRL-P and use CTRL-Y to accept a match.
NOTE: this step assumes you have Vim compiled with the Ruby interface (the output of :help version should include +ruby)
4. Happy hacking! You can complement the system-wide settings with plugins placed within your home directory. Inside the directories I see no need to tamper with syntax highlighting or indenting, but being able to have Vim load up a special configuration file whenever a Ruby file is loaded is a great benefit. In fact, it can load more than one file. Here are the three important files that Vim loads whenever I edit a Ruby program:
You can see the pattern there. When the filetype is “ruby”, Vim will load any files like those above. In my directory, ruby.vim sets textwidth, softtabstop, and shiftwidth. That’s it. (These are inappropriate for the system-wide ftplugin, because they reflect user preferences.) ruby_structure contains a set of insert-mode mappings that make editing Ruby code much easier. My favourite one is the following: This enables the following shortcut. Say I’m writing an if-statement. Having typed: I can hit Shift-Enter and will get: This saves typing and enables me to keep the program balanced. Of course it applies to I will provide all the details of my personal Vim/Ruby configuration in an appendix in the near future. (Well, that hasn’t happened because I haven’t actually written any significant Ruby code for a while.) Maybe it will be useful to adopt the 2 spaces indent Ruby rule. In case use this The following extension works with braces, too. Having typed: I can hit Shift-Enter and will get: Here’s the code: — PitCapitain?
In addition to above, I have found this quite helpful: — AnonymousRubyist previous link don’t works anymore, so here is the code: — github.com/thinhlvv For more information Get the latest released vim-ruby files from Vim-Ruby Configuration Files project Created: 23 Oct 2002 Last Updated: 12 Apr 2006 (DougKearns) Some questions Ruby Vimmers may be able to answer (put here as they may help others)[should these move to a /discuss page, or would that make editing this page more painful?]: Is there a way to debug ruby code running inside vim (like printing the backtrace, etc) ? With matchit you can jump to the balancing word def…end, if…else…end, but is there a way to jump to the enclosing syntactical structure, such as the def…end, or from def…end to the enclosing class…end structure? Can this be done without creating maps (which are harder to look up/remember and in vim there’s less namespace for them than in vi)? There’s no way I know of to achieve this. It could be done imperfectly with search patterns. Is there a way to jump to a method of a given class in the file, for example if there are many similar named methods in different classes in the said file? I think this is equivalent to asking if there is tags support for ruby, but I’ve not done much with tags. Exuberant ctags does support Ruby (see bottom of page for more), but I doubt it would be able to resolve names in the face of many options. Good for basic navigation, though, and Vim’s support for ctags is excellent. [Gnu Global] [Irish mirror] may help with this, though it doesn’t support Ruby at the time of writing (04-APR-2003). It does support vim though. What about [taglist] ? It works wonders for me (except the fact that it only does the current file) SimonVandemoortele |
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |