Wednesday, July 12, 2006

Vim 7.0 - Autocomplete With Rails

Just installed Vim 7.0 ...and had to check out this cool 'omnicomplete' thingy! Like ctrl-space in eclipse to complete methods, etc...

I tried a ruby file, and on first go it complained:
'load_buffer_class': uninitialized constant MyClassNameHere

I wonder how I can tell vim where my rails code lives?

Found this blog describing how to setup for c - the key for me was this comment:

–run ctags on your C libraries (from VIM :help ft-c-omni)


I checked out :help ft-ruby-omni and it's all there:

Vim can detect and load the Rails environment for files within a rails project. The feature is disabled by default, to enable it add
let g:rubycomplete_rails = 1
to your vimrc


So I needed to add that line to my .vimrc file....

However, here I am on windows, and unsure where the .vimrc lives. It's supposed to go in your home directory - which on windows is typically 'C:\documents and settings\*user_name*\'.

Turns out, you can use unix style shortcuts within vim and they work fine. This is useful because I can edit the home .vimrc file using the following from within vim:
:e ~/.vimrc

Then, when i save the file (:w) it saves it in C:\documents and settings\*user_name*\.vimrc - problem solved!

BUT, then syntax and other defaults were turned off.... I had lost my 'default' settings.

What I needed was to source the defaults - which in my install was sitting in my VIM root, and named "_vimrc".

My final ~/.vimrc file looks like this:

source $VIM/_vimrc
let g:rubycomplete_rails = 1


And now all is good! Now I just need to spend some quality play-time...

3 comments:

Furyz said...

Thanks a lot!

jake george said...

Ruby On Rails Online Training, ONLINE TRAINING – IT SUPPORT – CORPORATE TRAINING http://www.21cssindia.com/courses/ruby-on-rails-online-training-142.html The 21st Century Software Solutions of India offers one of the Largest conglomerations of Software Training, IT Support, Corporate Training institute in India - +919000444287 - +917386622889 - Visakhapatnam,Hyderabad Ruby On Rails Online Training, Ruby On Rails Training, Ruby On Rails, Ruby On Rails Online Training| Ruby On Rails Training| Ruby On Rails| "Courses at 21st Century Software Solutions
Talend Online Training -Hyperion Online Training - IBM Unica Online Training - Siteminder Online Training - SharePoint Online Training - Informatica Online Training - SalesForce Online Training - Many more… | Call Us +917386622889 - +919000444287 - contact@21cssindia.com
Visit: http://www.21cssindia.com/courses.html"

Adlearning Technologies said...

Thank You for sharing your article. I like it. We are also giving TIBCO Online Training at affordable prices.