Table of contents for Ruby IDEs
I know that the geeks amongst you would like to believe that only one text editor program exists in this world. Depending on which of the two groups you fall into, its either Emacs or Vi. Its a cool life for such people: they don't need to bother checking out the greatest and the latest of the development environments getting released in the market every day. Emacs and Vi always grow up to become the greatest editors soon after every technological innovation that takes place in the software world. They are stable, powerful, feature-rich, modular, customisable, extendable, ubiquitous and available in multiple flavours to suit the slightly different tastes even by the geek standards. The only downside of these two evergreen editors is the steep learning curve associated with them. But as with all great things, it more than pays off by the end.

In this article, we'll witness the support for the Ruby language present in the latest version of the Vim editor - Vim 7. If the latest version of Vim is not available on your preferred distribution(through its package manager, for example), then you can build it from the source, and install it in the user home directory if you don't want to mess up with the file organization of your package manager. Here is the procedure to install Vim 7.0 from the sources in the user's home directory. If you already have it installed, then skip to the next section.
Download the source package for Vim 7.0 editor. Extract it in the home directory and 'cd' into it:
sh# tar xvjf vim-7.0.tar.bz2
sh# cd vim70
Install using the usual method for building from the source:
sh# mkdir $HOME/vim7
sh# ./configure --prefix=$HOME/vim7 --enable-rubyinterp
sh# make && make install
Make sure that you run the above commands as an unprivileged user(non-root) so that the generated files get proper file ownerships. (Run the above commands as root and drop the '--prefix' option to install it in system directories and make it available to all the users.)
Now you can run the editor by running the command './vim' from the ~/vim7/bin directory. The procedure to run the vi editor can be simplified using one of the following techniques:
Add the 'bin' directory of Vim installation(~/vim70/bin in our case) to $PATH variable in the user's profile(~/.bash_profile). As root user, create links to all the executables present in ~/vim7/bin directory into the /usr/bin directory under different names(vim7, vimdiff7 etc so as not to conflict with the files from a possibly already existing Vim installation) and then run them from anywhere using these new names. If you have installed it in the system directories, then of course you don't have to worry about all these settings and can directly run the editor using the 'vim' command from any directory.
Configuring Vim 7.0 For Ruby Support
The first step that we had taken to get Ruby support in the Vim editor was to compile it using the '--enable-rubyinterp' configure option. To get complete support for the Ruby programming language in the Vim editor, we need to add the following lines to the Vim configuration file .vimrc present in the home directory.
[Create it if it's not already there; an easy way to do this is to make a copy the sample vimrc file that comes with Vim 7.0, i.e.
sh# cp /home/user/vim7/share/vimrc_example.vim /home/user/.vimrc
Then add the following lines at the bottom of the .vimrc file]
set nocompatible
syntax on
filetype on
filetype indent on
filetype plugin on
Creating & Running Ruby Programs Using Vim 7.0
Now you are set to create your first Ruby program in the Vim editor.
sh# cd ~/vim7/bin
sh# mkdir -p ~/progs/ruby
sh# ./vim ~/progs/ruby/first.rb
Type the following program in the editor.
RUBY:
class Greeting
def say(name)
puts "Hello, #{name}"
end
def shout(name)
puts "HELLOOOOOOO, #{name}"
def
end
greet = Greeting.new
greet.say("Marc")
The editor should now look like this:

Apart from the neat syntax colouring that is visible in the picture, the Vim editor also does automatic code indentation and helps in code completion too. You can even run the programs from within the editor. Let us see how to access these features in Vim.
Add one more method(optional) to the 'Greeting' class that we had created earlier and name it something starting with 's'. I have added a function called 'stash()'. Go to the end of the Ruby program and type 'greet.s' and stop - don't complete the function name. If you press the key combination Ctrl-X Ctrl-O at this stage, Vim will pop-up a list of possible completions of the code that you have typed until now and lets you select one of those options. Below is a picture demonstrating the same.

To run the Ruby program from the Vim editor, let's first introduce a small mistake in it: change the code from 'Greeting.new' to 'Greeting.ne' and issue the following command in the vi command mode(presss the escape key and type the following line):
:rubyf ~/progs/ruby/greet.rb


You should see the following error message displayed at the bottom of the Vim screen.

Now go back to the program and remove the error that we had introduced and re-execute the program. You should see the output of the program as shown below.

For more help on the Ruby support in the Vim editor, issue the ":help ruby" command and scroll through the information displayed.
End Notes
The biggest advantage of developing Ruby programs using the Vim editor is that one gets all the powerful features of the vi editor which we have been using for years and have completely gotten used to. If you are searching for an easy to learn and easy to use programming editor, then perhaps you need to search elsewhere(see links below for some options) but if you are primarily a vi user, or don't mind investing some time initially to get used to this powerful editor, then the Ruby support available in it should make it an ideal choice for developing Ruby programs.
Related Posts:
Develop Ruby Applications Using Vim 7.0...
"Emacs and Vi always grow up to become the greatest editors soon after every technological innovation that takes place in the software world. They are stable, powerful, feature-rich, modular, customisable, extendable, ubiquitous and available in multi...
Trackback by Anonymous — September 24, 2006 @ 11:40 pm
Should
--ebable-rubyinterp
be
--enable-rubyinterp
Thanks for the sound articles.
Don
Comment by Don — September 25, 2006 @ 8:46 pm
tabrez on September 25, 2006 at 9:03 pm said:
Oh yeah, of course. Thanks for pointing out the typo, it's corrected now.
Comment by tabrez — September 25, 2006 @ 9:03 pm
Hello,
I'm having trouble using the "configure" command.
[seanlerner]$ ./configure --prefix=$HOME/vim7 --enable-rubyinterp
-bash: ./configure: No such file or directory
Do I need to install "configure"?
I've tried searching for help on "configure", but the word is used so much I can't find a particular Unix application/command called configure.
Thanks,
Sean
Comment by Sean Lerner — October 10, 2006 @ 9:43 pm
Sean Lerner,
You don't have to install anything: just first change to the directory of the extracted vim folder and then run the './configure' command.
sh# tar xvjf vim-7.0.tar.bz2
sh# cd vim70
sh# mkdir $HOME/vim7
sh# ./configure --prefix=$HOME/vim7 --enable-rubyinterp
sh# make && make install
The step to 'cd' into vim70 was missing from the post; I have added it now.
Comment by tabrez — October 11, 2006 @ 3:50 pm
Hi Tabrez,
Thanks--that worked.
I've run into a new problem now. When I run:
make && make install
...
...
objects/os_unix.o objects/pathdef.o objects/popupmnu.o objects/quickfix.o objects/regexp.o objects/screen.o objects/search.o objects/spell.o objects/syntax.o objects/tag.o objects/term.o objects/ui.o objects/undo.o objects/window.o objects/if_ruby.o objects/netbeans.o objects/version.o -lncurses -lnsl -ldl -lruby-static -ldl -lcrypt -lm
/usr/bin/ld: cannot find -lruby-static
collect2: ld returned 1 exit status
make[1]: *** [vim] Error 1
make[1]: Leaving directory `/home/.grotton/seanlerner/vim70/src'
make: *** [first] Error 2
[vim70]$
I'm using dreamhost, btw.
Any suggestions? (even pointers to the appropriate manual is appreciated)
Thanks,
Sean
Comment by Sean Lerner — October 11, 2006 @ 9:09 pm
Are you sure that Ruby is installed on the machine? If not, install the ruby package first and then repeat the above steps. Help on installing Ruby on various GNU/Linux distros is available here:
http://beans.seartipy.com/category/ruby/
If you don't want to install ruby support for Vim and want to use it for some other purpose, then you can drop the –enable-rubyinterp option when configuring its installation:
sh# ./configure –prefix=$HOME/vim7
sh# make && make install
Comment by tabrez — October 12, 2006 @ 9:24 pm
Oh yes, I'm sure Ruby is installed on the machine:
[log]$ ruby -v
ruby 1.8.4 (2005-12-24) [i686-linux]
[log]$
And I'm purposely doing it to take advantage of the coloured ruby code.
Right now I'm using dreamhost.com's VIM (version 6.3.82) and editing ruby, and it's all one colour. It would be really nice to have the extra ruby support available in VIM. Maybe another option is to add it to the current version of VIM that I'm using (that's installed system wide)?
Any pointers appreciated,
Sean
Comment by Sean Lerner — October 12, 2006 @ 9:32 pm
I don't know of a way to add ruby support by making changes to the Vim configuration files. For full Ruby support, VIM has to be recompiled with the appropriate option.
The error "cannot find -lruby-static" pretty clearly states that it couldn't find the ruby-static library file(search for libruby-static.a file in LIB directories). To confirm this fact, you can do a test install by dropping the –enable-rubyinterp option when running the configure script - Vim should get installed without any problems in this case. I don't know which distributions use the ruby-static library(neither ubuntu nor gentoo install them with the Ruby package), perhaps it is part of the Ruby package for RPM based distros(fedora, suse etc).
Here is the only page where I was able to find an RPM package for ruby-static:
http://rpm.rutgers.edu/rpm2php/?id=1781
and it is for Solaris 2.9 UltraSPARC. The library might be a part of a different RPM package for other distributions.
Comment by tabrez — October 15, 2006 @ 9:30 pm
Hello,
I just thought I'd let you know that I decided to stop using dreamhost, as it was very slow, and I bought a virtual server package from vpslink.com and I've installed ubuntu on there. I used your procedure and I now have vim7 running successfully.
Thanks,
Sean
Comment by Sean Lerner — November 9, 2006 @ 1:45 am
vpslink.com seems to be too cheap for VPS hosting. Nice find! It is not as easy to install our own applications on Dreamhost as it only gives user access on its servers, and root access would be more desirable for managing all the dependencies for applications like Vim.
Comment by tabrez — November 13, 2006 @ 1:44 pm
The syntax highlighting in your screenshots uses dark colours that are designed to be seen against a white background, not a black one like is used in your screenshots.
To fix this, use this command (and put it into your .vimrc)
:set background=dark
This tells vim to use bright colours for syntax highlighting.
Comment by Jimbo — December 7, 2006 @ 12:28 am
To run the Ruby program currently edited,
you can do this; '%' stands for the current filename:
:rubyf %
or
:!ruby %
(slightly different output from the above)
Comment by taki — April 27, 2007 @ 8:57 pm