dnite’s ‘old’ Blog

For my new blog, head over to http://blog.dnite.org

  • Moved Out!

    Thanks for stopping by my blog! It's been fun over here at Wordpress.com but I've moved to bigger, better things. My new blog is located here! Hope to see you there!

  • Advertisements

More Ruby on Rails with Ubuntu… (rails.vim)

Posted by dnite on November 10, 2006

UPDATE: I have updated this entry on my new blog at blog.dnite.org. That link is a direct link to the updated article.

I wrote an article not too long ago about installing Ruby on Rails on Ubuntu (Edgy) quickly and easily. The one section I left pretty ‘in the air’ was definitely the IDE. I feel that Linux has the biggest choice when it comes to editor options.

If your using Windows, you’ll probably use RadRails. It’s feature rich. It does everything you need. And windows Java machine just seems to work more efficiently, in my experience, than the ones for linux. If anyone wants to give me some hints to improve my java machines performance, go right ahead. On the mac. You have TextMate. Mac’s also have a lot of options, but from what I’ve heard and seen. Very seldom do you develop Rails applications on a mac without using textmate.

Now, for Linux, you have a variety of things to choose from and I’ve dipped my hands in a few of them. First, I tried RadRails. RadRails is what I used in windows and it was familiar to me. Since it runs on all 3 platforms, I figured I’d give it a shot in Linux. The problem was, that it just seemed a lot slower than it ran in Windows. I’m not exactly sure why this is, but speed and reliability were the reasons I went looking for a better alternative. I did some research and found that some people used jEdit. But getting jEdit to work in Edgy was a chore, do I didn’t even try. gEdit was also another option. It highlights syntax. It can take plugins. It’s a pretty light weight editor. I tried this for a couple of days, but it just didn’t feel right.

Over in the #rubyonrails IRC channel on irc.freenode.net, I heard about vim and a plugin called rails.vim. I’d given vi a try a long time ago. But never a substantial try. It was always really confusing to get into right away. It’s just not like most other editors. But I figured I’d give it a shot anyways. After a week or so of working with Vim and rails.vim, I’m pretty sold. I’m not 100% comfortable with it just yet, but I can definitely see the potential. I find myself hitting ESC and starting to type :wq when quickly editing something in gEdit or something. Rails.vim takes vim a step further and adds a ton of nice Rails features. Here’s what I did to get into and start enjoying using vim in a couple of days.

First and foremost. Make sure you have Vim installed. Pretty simple. The vimtutor command is optional but VERY VERY recommended if you’ve never used vim. Take the half hour to complete the tutor and you will understand vim a lot better.

sudo apt-get install vim-common vim-runtime vim-gnome

Now that you have vim installed, let’s install the vim ruby gem that gives you all the nice syntax highlighting and other cool ruby features. When you run vim-ruby-install.rb, it gives you the option to install to your home folder. I picked this option, so make sure you don’t run this with sudo.

sudo gem install vim-ruby --remote
(select option 1 when it asks where you want to install. /home/username/.vim)

Now you should have Vim installed with some nice ruby stuff. Let’s go ahead and make a startup file to get rid of a few vim annoyances. Create a new file called .vimrc in your home directory (~/.vimrc) and add the following.

set nocompatible
syntax on
filetype plugin indent on
set mouse=a

runtime! macros/matchit.vim

augroup myfiletypes
autocmd FileType ruby,eruby,yaml set ai sw=2 sts=2 et
augroup END

Now, all we have to do is download rails.vim. Head over to rails.vim and download the latest version. There should be a plugin directory and a doc directory in this archive. Extract it to your .vim folder and your all set. The last thing you have to do is enable the rails documentation.

:helptags ~/.vim/doc

With rails.vim installed, you can launch vim from your project directory and have a lot of new functions. If you try :Rmodel user (which tab completes very nicely), it opens up app/models/user.rb. :Rcontroller blog will open up app/controllers/blog_controller.rb. Everything works just like you would expect it to. You can tab complete the commands and the filenames. If you don’t know what file your looking for, leave the filename off and start hitting tab. You’ll just cycle through all the models or controllers or views. :Rextract will take a currently highlighted section of your code, and automatically create a new partial file while replacing the current selection with the render :partial call. Also, if you move the cursor over another controller name or model name or anything similar and press gf, you will open up that file. It takes a little getting used to but it really works. For a completely list of everything that rails.vim can do, type :help rails. There’s a lot you can do.

Hope that helped out some people! Enjoy!


10 Responses to “More Ruby on Rails with Ubuntu… (rails.vim)”

  1. RadRails is basically Eclipse plus plugins. If Eclipse runs fine on your machine, try installing the RadRails plugins.

  2. dnite said

    Ya, I know that RadRails is just Eclipse with plugins. I tried to install Eclipse and just add the plugins when I was still running windows and it didn’t work out so well. So I never really bothered again. I may give RadRails another shot when new versions come out, but I’m quite happy with Vim… x=)

  3. […] EDIT: I actually did a new piece on using Vim as your ‘IDE’ for rails. Take a look. […]

  4. Flink said

    Hey there, nice post.

    But I don’t understand a thing: why you’re using a gem for vim-ruby since there is a “vim-ruby” package in Edgy ? 🙂

  5. dnite said


    Ya, I could have used the edgy package for vim-ruby, but just to keep pace with their own development cycle, I install the gem. I really don’t think it matters. Anyone can use either the gem or the deb package.

  6. Flink said

    Ok ok then, thanks 🙂

  7. jonny said

    The reason that RadRails feels slow on Linux is that there’s a bug caused by differences in the way that Windows and Linux treat shortcuts / symlinks. Each Rails project has a recursive symlink in that ProjectDirectory/vendor/rails points to itself, and, on Ubuntu, Radrails goes wild trying to find the end of the loop. This pushes CPU utilisation up to 100% and causes repeated memory overflows in the JVM.

    The answer is to delete the ProjectDirectory/vendor/rails link in each project, and to replace it with an identically named real folder. You then need to take a copy of all of the files in the ProjectDirectory/vendor folder and copy them into the new folder that you’ve just created.

    After using that hack, I find Radrails more responsive and generally more pleasant to use on Linux than on Windows.

  8. Brandon said

    Thanks for the post, it was a life saver. I tried for about 2 hours to figure out how to implement vim-ruby before I came across your site. How did you know what the startup script (.vimrc) needed to have in it? I wasn’t able to find any documentation from vim-ruby’s site.

    Anyway, thanks again. I too run on Edgy and will certainly keep an eye on your site for future tips.

  9. dnite said


    I got the ‘code’ for the .vimrc from a combination of wiki.rubyonrails.com and just added a few things that I like to have as well… I’m glad it helped. x=)

  10. Dru Nelson said

    Very helpful. Got the nice syntax highlighting that I was
    used to having from RedHat. Thanks!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: