Updated on February 06, 2010 to account for updates in pathogen.vim 1.2
Updated on February 10, 2010 to account for set up difficulties some Linux users were experiencing
Now that I have your attention, I've come across quite a few blog and forum posts from people looking for "the best" text editor or IDE to use for Ruby on Rails development. I was fortunate enough to meet Tim Pope soon after I got interested in Rails and was subsequently introduced to the awesomeness that Vim is capable of. It took some ramp up time to get comfortable with modal editing but now I find myself frustrated when I don't have all the power that comes from Vim's modal mindset.
Flame War Disclaimer
What you use to edit code is any other tool and it comes down to personal preference. Personally I LOVE Vim. There are hundred different ways you could set up Vim. This is the setup that's worked best for me. Hope you enjoy it as well.
First things first
Install MacVim or Gvim (For Debian based distros install with apt-get). I do frequently use terminal Vim or Vi but I like having both available. If you're on Windows you probably want to spin up a Linux box or a VM. Ruby on Rails development on Windows is going to painful.
Let's Get Plugged In
Download pathogen.vim it makes managing Vim plugins a lot simpler. Create a ~/.vim/autoload/ directory and copy pathogen.vim into it.
Create a .gvimrc to specify colorscheme
http://www.vim.org/scripts/script.php?script_id=2340
Create a ~/.vim/bundle directory and install plugins. I prefer to clone them from github.com when I can. Some plugins still need to be downloaded from vim.org, extracted and copied to your .vimbundles directory. Either way go vote up plugins you find useful on vim.org. If you don't have git installed check out git-scm.com
Technorati Tags: vim, ruby, rails

Updated on February 10, 2010 to account for set up difficulties some Linux users were experiencing
Now that I have your attention, I've come across quite a few blog and forum posts from people looking for "the best" text editor or IDE to use for Ruby on Rails development. I was fortunate enough to meet Tim Pope soon after I got interested in Rails and was subsequently introduced to the awesomeness that Vim is capable of. It took some ramp up time to get comfortable with modal editing but now I find myself frustrated when I don't have all the power that comes from Vim's modal mindset.
Flame War Disclaimer
What you use to edit code is any other tool and it comes down to personal preference. Personally I LOVE Vim. There are hundred different ways you could set up Vim. This is the setup that's worked best for me. Hope you enjoy it as well.
First things first
Install MacVim or Gvim (For Debian based distros install with apt-get). I do frequently use terminal Vim or Vi but I like having both available. If you're on Windows you probably want to spin up a Linux box or a VM. Ruby on Rails development on Windows is going to painful.
Let's Get Plugged In
Download pathogen.vim it makes managing Vim plugins a lot simpler. Create a ~/.vim/autoload/ directory and copy pathogen.vim into it.
$ mkdir ~/.vimNext you need to create and edit your .vimrc file so that pathogen gets loaded in the correct order.
$ mkdir ~/.vim/autoload
$ cp ~/Downloads/pathogen.vim ~/.vim/autoload/
$ mvim ~/.vimrcContent:
filetype offThe "filetype off" is necessary for some Linux distros. If you're on OS X you should be able to omit that though it won't hurt either way if you leave it in.
call pathogen#runtime_append_all_bundles()
syntax on
filetype plugin indent on
set tabstop=2
set smarttab
set shiftwidth=2
set autoindent
set expandtab
Create a .gvimrc to specify colorscheme
$ mvim ~/.gvimrcContent:
colorscheme vividchalkI've also become fond of the molokai colorscheme. But its all personal preference. You can also forgo the .gvimrc file and just specify your colorscheme in .vimrc but if you are using terminal vim loading some colorschemes doesn't work very well. Putting it in the .gvimrc will only load the custom colorscheme when you are in Gvim or MacVim.
http://www.vim.org/scripts/script.php?script_id=2340
Create a ~/.vim/bundle directory and install plugins. I prefer to clone them from github.com when I can. Some plugins still need to be downloaded from vim.org, extracted and copied to your .vimbundles directory. Either way go vote up plugins you find useful on vim.org. If you don't have git installed check out git-scm.com
$ mkdir ~/.vim/bundleInstall rails.vim
$ cd ~/.vim/bundle
$ git clone git://github.com/tpope/vim-rails.gitInstall cucumber.vim
$ git clone git://github.com/tpope/vim-cucumber.gitInstall vividchalk.vim
$ git clone git://github.com/tpope/vim-vividchalk.gitInstall haml.vim (There are two. I use Tim Pope's.)
$ git clone git://github.com/tpope/vim-haml.gitInstall endwise.vim
$ git clone git://github.com/tpope/vim-endwise.gitInstall surround.vim
$ git clone git://github.com/tpope/vim-surround.gitInstall unimpaired.vim
$ git clone git://github.com/tpope/vim-unimpaired.gitInstall abolish.vim
$ git clone git://github.com/tpope/vim-abolish.gitInstall repeat.vim
$ git clone git://github.com/tpope/vim-repeat.gitInstall NERD_tree.vim
$ git clone git://github.com/scrooloose/nerdtree.gitInstall NERD_commenter.vim
$ git clone git://github.com/scrooloose/nerdcommenter.gitRestart Vim and you now have a super powerful Rails editor at your fingertips. Check out each of the plugins for documentation of features.
Technorati Tags: vim, ruby, rails

With a little bit of @tpope's help, I came up with this install script. I think you'll like it: http://bit.ly/3DeRUn
ReplyDeleteNice.
ReplyDeleteIf your looking for a good setup for windows and gvim, check this out. http://akitaonrails.com/2009/1/13/the-best-environment-for-rails-on-windows
ReplyDeleteYou can also get a sweet vim setup via github. Check out my vim files here:
ReplyDeletehttp://github.com/kevincolyar/vimfiles
I love Vim for Ruby, but didn't know Endwise. Thanks for that.
ReplyDeleteAlong, the same lines I'm a big fan of AutoClose. It gives you auto-insertion of closing halves of {, [, (, " and '.
The point of pathogen.vim being in autoload is that you don't have to manually source/runtime it before using its functions.
ReplyDeleteAnd there's no need to source gvimrc from vimrc. Gvim/MacVim loads it anyway.
graywh, you actually do need to manually source/runtime for this setup to work. That is straight from Tim Pope, the author of pathogen.vim and I have tested to confirm.
ReplyDeleteYou don't have to source .gvimrc from vimrc and will work fine. That's up to personal preference on formatting I want displayed when I'm in terminal vim.
Updated the post per a clean up of my dot files today after a conversation with "the Pope"
ReplyDeleteWow... I use vim daily for rails work but always felt like I could go beyond just FuzzyFinder and NerdTree. Thanks for seriously pimping my ride!!!
ReplyDeleteScreenshots!
ReplyDeleteScreenshots of what?! (Also, why are we yelling?)
ReplyDeleteSerious question--I have been thinking about learning vi/vim but with this setup, what do I do to breakpoint and step-through ruby/rails code?
ReplyDeleteYou might want to check out http://github.com/astashov/vim-ruby-debugger I haven't used it but could provide what you're looking for.
ReplyDeleteVim is awesome, after you have spent a month memorising keyboard shortcuts. Most people give up after 5mins.
ReplyDeleteOf course true geeks never give up.
P.S: I still prefer aptana :)
great stuff, but PLEASE post follow-up with some of the more popular techniques/key-commands you use for jumping around in a rails project and being productive. i've tried to make the jump from textmate to vim several times but i keep giving up because it's just SO much faster to jump between files in textmate (e.g. command-t vs. :Rmodel blahblahblah).
ReplyDeleteWhat about integrate version control?
ReplyDeleteThanks for this, I hadn't come across pathogen for some reason. I hope everyone who finds tpope's scripts useful has donated a few bucks through his github pledgie.
ReplyDeleteCheers,
Chris
trak3r, you can use gf in a lot of situations (go to file) but I have been meaning to do a follow up to my Vim Cards post with the more specific Rails features. Here is the set for my core Vim commands I use.
ReplyDeletehttp://www.adamlowe.me/2009/07/vim-cards-how-i-learning.html
Also if you're in Jacksonville, FL you should stop by the Hashrocket Offices and let Tim Pope and Veez show you just how fast editing Rails in Vim can be.
vimrails.org, If you're using git then check out Tpope's fugitive.vim
ReplyDeletehttp://github.com/tpope/vim-fugitive
While this post is helpful, it would be 100x more so if you recorded and posted a screencast demonstrating how you use your setup.
ReplyDeleteI've never manually sourced it and my setup works just fine.
ReplyDeletesilent! call pathogen#...
graywh is correct about the explicit runtime and guard clause not being strictly necessary. I often do it in example files so that things don't blow up if pathogen.vim isn't installed.
ReplyDeleteNice writeup. I've redone my vim setup to follow and really like the vimbundles setup.
ReplyDeleteI did add the following to my vimrc to use a shortcut for NERDTree:
let mapleader = ","
map nt :NERDTree
Do you have any more shortcuts like this?
Thanks again for the writeup!
I pretty much just use the keymaps from the plugins listed above, standard Vim, and other then that just what I've put in slurper.vim for story cards.
ReplyDeleteGreat stuff! Now I'm trying to switch to Vim, thanks for this article Adam
ReplyDeleteI stand corrected by graywh and The Pope. I have amended the .vimrc content accordingly. You can indeed simply use:
ReplyDeletecall pathogen#runtime_prepend_subdirectories(expand('~/.vimbundles'))
Check out snipMate too ... http://www.vim.org/scripts/script.php?script_id=2540 (I had to type that in by hand so if it doesn't work, just look for snipMate on vim.org). It's been a huge help for ruby (and indeed all language development) for me.
ReplyDeleteNote to moderator, the leader stuff and cr commands that have angle brackets around them are probably going to be stripped out, so if that doesn't come through, you might not want to post or it will mislead.
ReplyDeletelet mapleader = "," Easier to reach fingers
map t :execute 'NERDTreeToggle ' . getcwd() Toggle nerdtree
map r :TlistToggle Toggle ctags
Tlist_Use_Right_Window = 1 Opens Tags in the "right" window, and nerdtree is in left.
map g :FufFile**/ Toggle FuzzyFile Finder
map b :FufBuffer**/ Toggle FuzzyBuffer Finder
map s w Jump from screen to screen, such as Nerdtree to main window and then to ctags window.
nmap n :tabnew New Tab
nmap :tabn Tab Next
nmap :tabn Also Tab Next
nmap :tabp Tab Previous
namp :tabp Also Tab Previous
nmap :tabclose close tab
nmap :C-]> : easier jumping to links/files under the cursor
nmap w :on easy close all windows but primary one you are in
Another big one is I have supertab completion on, and set to complete on , to autocomplete words and snippets.
nmap a :!exctags -R --exclude=.svn --exlude=.git --exlude=log * easy ctags regeneration
autocmd TabLeave * wincmd p auto open and close Nerdtree
autocmd TabEnter * NERDTreeMirror same
autocmd TabEnter * wincmd p same
I also use folding, but the commands are easy on my fingers, so I don't remap.
The learning curve for Vim on Rails is too high. It puts me off. I mean, are you saying I have to download ALL those plugins and read about them before I can use them? there's a lot of plugins.
ReplyDeleteSomeone should package all this up into an easy to use interface. Configuring VIM and selecting/finding decent packages should surely be made easy to do?
Too high for what? If you are a developer or serious about learning software development the above set up IS simple. There is no quick, easy path to learning a powerful tool like Vim or a complex craft like software development.
ReplyDeleteHeads up folks due to some updates to pathogen.vim you'll need to make some changes to your setup if you want to update to pathogen.vim 1.2. I've amended the instructions above accordingly.
ReplyDeleteBut why does Vim destroy all other Rails editors?
ReplyDeleteThe speed and features it provides are far better than any of the other editors out there IMO. Modal editing is much more pleasant and efficient than having to context switch to slower mouse movements required by most of the other editors. Again it's person preference and this is mine. The title was meant to be a hook to generate interest and discussion.
ReplyDeleteThanks for this interesting post about your vim config.
ReplyDeleteI installed all the plugins you suggested and adjusted my .vimrc according to your instructions.
The plugins are working fine, but I could not get the helpfiles working. I'm wondering if this might be an issue with the way the plugins are loaded using pathogen?
Does vim-cucumber work with pathogen? I'm not gettin any of the features nor syntax highlight once cloned into the bundle dir (The other plugins seem to work like a charm).
ReplyDeleteIt does indeed work with cucumber. Some users on debian based linux distros have experienced an issue that can be resolved by amending your .vimrc as follows:
ReplyDeletefiltype off
call pathogen#runtime_append_all_bundles()
syntax on
filtype plugin indent on
It looks like debian turns filetype on automatically for you before it calls pathogen and is what causes the problem. This turns it off, calls pathogen and then turns it back on. Should fix your issues.
Thank ya.
ReplyDeleteBut, bhould it be `filetype` and not `filtype`? Was getting some errors when I tried this verbatim.
@roman to generate all the help docs try
ReplyDelete`:call pathogen#helptags()`
This will generate the help files for the bundles
J. Weir, thanks for heads up on the typo. Corrected.
ReplyDeleteHey Adam, this is great, I was wondering why you or others aren't using git submodules for this?
ReplyDeleteThere was a question about using Git submodules for this setup. For some reason it didn't show up after approving.
ReplyDeleteI'm not a fan of submodules in general. Just haven't found a good justification yet. I wanted to give people a good foothold of the core items they would need to get a solid Ruby and Rails editor with Vim but not tie them to any of them or a certain way of installing/maintaining, especially one that might confuse newer folks.
You could do submodules or just script it out and have an alias for your script. We have scripts for our core setup at Hashrocket. I update incrementally as necessary.
Definitely the best development environment. I love VIM and VIM + Rails looks good with Rails.
ReplyDeleteI really like this setup. Simple yet elegant and exactly what i need.
ReplyDeleteI'm getting issues with the vim-cucumber. I have the amended .vimrc file:
ReplyDeletefiletype off
call pathogen#runtime_append_all_bundles()
syntax on
filetype plugin indent on
But I still get no syntax highlighting for my .feature files. The identing seems to be working though.
I experienced an issue after the latest MacVim update and have since uninstalled and then reinstalled via homebrew which solved my problems with stuff not loading properly from my .vimrc.
ReplyDeleteTry this in your .vimrc file:
runtime! autoload/pathogen.vim
if exists('g:loaded_pathogen')
call pathogen#runtime_prepend_subdirectories(expand('~/.vimbundles'))
endif
syntax on
filetype plugin indent on
if filereadable(expand('~/.vimrc.local'))
source ~/.vimrc.local
endif
I would have a look at installing through Hashrocket's dotmatrix if that doesn't work.
http://github.com/hashrocket/dotmatrix