04
Rails on Vim (in English)
on January 04, 2009
Update 04/27/09: I made some updates that you can read about here
I’ve been thinking this through for a while about what are the best tools to develop Ruby and Rails project outside of the Mac. Specially on Windows. Netbeans and Eclipse Aptana are good choices and they are evolving fast, but I always thought of Java based IDE to be heavier than necessary.
I always say that you only need a good text editor and the terminal. But on Windows there is not that many competent editors such as Textmate. Even on the Mac, there are those who don’t want to pay for Textmate.
Railers have recently started to talk about Emacs, including Geoffrey who just released a great Peepcode screencast about it. Personally, I don’t feel like getting used to Emacs. It is just a personal taste thing, but I always preferred Vim.
On the other hand I never really stopped to configure Vim decently. So I spent a couple of days researching the Web, looking for the pieces to make Vim behave more like Textmate. At Github there are many configurations. I got one that I felt more complete and I did my own fork. I spent a day converting Textmate snippets to NERDSnippets in Vim, including the bundles for Ruby, Rails, Javascript, Rspec, jQuery. The end result is something very similar, though Textmate’s snippets engine is still ahead of NERDSnippets. Jamis Buck’s FuzzyFinder adaptation is also a great replacement for Textmate’s file navigator.
To install it on the Mac, you should not use the built-in Vim because it doesn’t come with the necessary Ruby bindings. Download MacVim. Then, in your ~/.bash_profile type in the following:
1 2 3 4 5 6 7 |
On Windows, download "gVim":http://www.vim.org/download.php#pc. On the Mac and Linux you should have a .vimrc file and .vim folder under your home directory (ex. /Users/akitaonrails). On Windows you must have a _vimrc file and vimfiles folder also under your home directory (ex: c:\Documents and Settings\akitaonrails, on Windows XP or c:\Users\akitaonrails, on Vista and Windows 7). On the Linux and Mac, from your home directory, do: <macro:code>git clone git://github.com/akitaonrails/vimfiles.git ~/.vim cp ~/.vim/vimrc ~/.vimrc |
On Windows, also from your home directory, do:
That’s it. Now, from inside Vim, do ”:helptags ~/.vim/doc ( ~/vimfiles/doc, on Windows) and then rails to learn more about Tim Pope’s Rails.vim plugin. You can use surround, nerdtree” to learn more about the other bundled plugins as well. Rails.vim gives you commands such as :Rgenerate that calls script/generate, :Rake for rake tasks, :Rscript for other script/* inside your Rails project, and so on and so forth.
Rails on Vim – English from Fabio Akita on Vimeo.
Ctrl+t is FuzzyFinder, the equivalent to Commant+T on Textmate. Then ”\+p” (backslash and “p”) brings up the Nerd Tree, which resembles Textmate’s Project Drawer. You can close it with just “q”. “R” (uppercase “R”) refreshes it and “o” (lowercase “o”) opens the folder/file your cursor is currently over. Finally, while editing your Rails files you can try the very same abbreviations from Textmate. To find out all the abbreviations, take a look at the .vim/snippets folder. There you will find sub-directories for each file type. For instance, .vim/snippets/ruby-rails/hm.snippet means that if you type “hm[tab]” inside a model file, if will activate the “has_many” snippet (see on my screencast).
To learn a little bit more about Vim editing, read the Why, oh WHY, do those #?@! nutheads use vi? article. Vim is very powerful and has lots of options that you will learn and get used to very fast.
On the Mac, I don’t think I will be dropping Textmate any time soon, but if I need to use either Linux or Windows, that’s definitely my primary choice. On Linux it is a no-brainer, and on Windows there is basically no decent text editor built-in (Notepad should’ve been dropped as a built-in app more than a decade ago, because it is so bad).
Do you have more cool tips on Vim to share? Don’t forget to comment.






You had me until the last two paragraphs!
What TextMate features are you missing that keep you from using Vim full-time?
I was also surprised to see that you use the built-in commands like :w instead of Command-S, which also works in MacVim.
@geoffrey haha to be honest it is pure laziness which keeps me in textmate. As I said Nerdsnippet is not a complete snippets solution. FuzzyFinder seems to explode a few times. But I will be forcing myself to get used to it for the time being. And you’re right I am not using MacVim’s shortcuts because I expect people to try this out on Windows also.
Nice post, didn’t know about NERDSnippet, Scrooloose is a Vim Script genius. Thanks for all the snippets. I been sticking to Vim and Emacs while everyone was messing around with TextMate and it’s nice to see so many coming back.
Great article, I was looking for something like this. Stumbled: http://www.stumbleupon.com/url/www.akitaonrails.com/2009/1/4/rails-on-vim-in-english
Wonderful article and video. I can’t wait to try this out tomorrow while working on my latest project. You posted this just in time!
Great Article,
I actually converted myself back to vim 2 weeks ago, and I love it. I was kinda like you, used vim back in the old days, and used textmate for the last years. Now that emacs is on the return with the “cool” kids i decided to give vim another try and look for some plugins which will fill my needs. I currently use:
Rails plugin
Project plugin (works together with rails plugin),
fuzzyfinder with fuzzyfinder_textmate,
snippetsEMU and
IndentAnything with Javascript (for correct indenting with javascript classes)
Really really love it :)
Emacs & Vim are matters of personal / team taste. we like both
That’s a good job of collecting all the vim files, creating snippets etc. I am a visual learner and I liked it very much and learned a lot, thanks a lot, Fabio!
Just one comment. Did you try out Vimmate? It has a nice drawer panel and a terminal, and, of course all the goodness of vim included.
Why don’t you use softlinks to the .vimrc in the git repo? All Unix’s support them, and Vista supports them, too. So they are an option for many developers.
JD
@jim deville: I agree.. softlink/simbolic link is a better solution instead of copying the whole file.. Actually I did it on a similar project that I created(http://code.google.com/p/l30-environment/source/browse/#svn/trunk/vim) when I check it out for the first time.
Just went through your screencast and my ctrl-t isn’t working. I’m getting a “E73: tag stack empty” error. I’m using MacVim. Anyone else have this problem?
@Kevin sometimes I stumble upon the same thing. Dunno why but if I open another file using the Project Viewer and then retry the fuzzyfinder keybind (which is Ctrl+F by default on the github repo) then it works. Very weird and a probable bug in the fuzzyfinder plugin.
Thanks for the help. ctrl-t still isn’t working for me but ctrl-f is. Guess I’ll just use that. Another problem I ran into was that fuzzy finder was bombing because the pwd of vim was my home directory, not my where my NERDTree was open to, and I assume it was choking trying to crawl that many files. Once I cd’d to my rails project it worked fine.
Sorry, trying to set up my gVim install now… getting a E492: Not an editor command: FuzzyFinderTextMate when I do ctrl-f. Tried ctrl-t and still get the ‘tag stack empty’ error.
@Kevin, dunno if it will help but I would suggest to start from scratch and follow the instruction I just updated here: http://www.akitaonrails.com/2009/1/13/the-best-environment-for-rails-on-windows.
Another important thing: make sure you have “C:\Ruby\bin” added to your PATH environment variable.
That was the problem. I was using gVimPortable and ruby in a cygwin environment. Worked once I installed ruby for windows. Thanks
Thanks very much for the video and the Vim configuration. I was installing some of the plugins a few weeks ago but was too lazy to read the documentation and haven’t found a video which shows the features of Vim and the plugin. You could also add the shoulda.vim filetype file. Ctr+t isn’t working for me but Ctrl+f. \p to open the nerdtree doen’t work, which might have to do with the german keyboard layout.
I’m using this setup on all platforms and it works great except the snippets aren’t working and the surround plugin isn’t ending my quotes and brackets, and I can’t use= and - in my rails views for <= => and <% -%>, respectively.
Anyone having these problems?
This RubyMine looks promising.. http://www.jetbrains.com/ruby/features/ruby_rails.html
I bet you’ve never tried E-texteditor or InType on windows. Both ride heavily on the Textmate paradigm with bundles and an extensible architecture.
http://intype.info http://e-texteditor.com
They’re both great projects with devoted developers.
if you’re only on windows www.e-texteditor.com might be an alternative. it uses “textmate-packages”, ...
though it seems to be kinda stale, since there’s only one developer :)
Great article Fabio, but I have to disagree with you that E Text Editor feels hacky and buggy. It’s been very stable and usable for a while now. I use it every day and have very, very few problems with it. Many Textmate bundles are included with the default install (including the Rails bundle) and have had most, if not all, of the major wrinkles ironed out of them. Many bundles work straight out of the box from the Textmate repo. Furthermore, the bundles editor is much much better than the one found in Textmate (E’s bundles editor actually uses the editor, rather than an annoying little dialog box).
Needed to change line 56 of fuzzyfinder_textmate.vim file for my Windows set up…
require ”#{ENV[‘HOME’]}/vimfiles/ruby/fuzzy_file_finder.rb”
I was getting error messages when starting GVim
Excellent Vim for Rails development screencast.
PS In the screencast, every time you mention comma, I think you mean colon :)
Thanks for such excellent screencast. How can I mange to paste from the clipboard in Linux?
hi, i follow this steps but i cant have the same functions.
I dont have the word help for rails commands, i put ”:help rails” and say to me they dont have any help.
How i can check if i do right all the steps or check that?
In fact ,the button set in your .vim of Fuzzy is isn’t it? =。=
Out of date:
vimfiles\snippets.vim.win32 is not in the git clone (anymore?).
You don’t even need a .vimrc file. Vim will autoload the files in the .vim/plugin folder in order.
What I do is put the .vimrc file in ~/.vim/plugins/1.vim and then vim will autoload that file.
Now my entire config is in a git repo and I don’t have to do the extra symlink step. (note this works on mac/linux)
I also had to install the ncurses-term package on ubuntu in order to get it to stop throwing an error about "gnome-256color".
<pre><code>
nnoremap <c-f> :FuzzyFinderTextMate<CR>
</code></pre>
changed it to use CTRL-t instead:
<pre><code>
nnoremap <c-t> :FuzzyFinderTextMate<CR>
</code></pre>
I just cloned the git repo, and it seems the snippets dir is empty. NERDSnippets also do not work. Are these symptoms related? :)
how can i get rid of '$ at the end of each line?
its annoying and confusings
I would like to disable the auto completation thing.
It slow down when you are trying to type symbols. It tries to do more than 10k matchs.
And I can't get snippets to work.
c:users\kristian\vimfiles>git submodule init
c:users\kristian\vimfiles>git submodule update
And got a snippets dir inside vimfiles, but where is the snippets.vim.win32?
I guess snippets.vim.win32 is the snippets directory?
Then I should perhaps do:
c:users\kristian\> copy vimfiles\snippets vimfiles\after\plugin\snippets.vim
??
C:\Users\kristian>copy vimfiles\snippets vimfiles\after\plugin\snippets.vim
vimfiles\snippets\readme.txt
Overwrite vimfiles\after\plugin\snippets.vim? (Yes/No/All): N
vimfiles\snippets\support_functions.vim
Overwrite vimfiles\after\plugin\snippets.vim? (Yes/No/All): N
0 file(s) copied.
C:\Users\kristian>
Now when I start up vim I get errors. NERDsnippets are not installed I guess?
Error detected while processing C:\Users\kristian\vimfiles\af
ter\plugin\snippets.vim:
line 1:
E492: Not an editor command: This repo contains a
collection of snippets to use with the NERD snippets
line 2:
E492: Not an editor command: plugin (http://github.com/scr
ooloose/nerdsnippets).
line 4:
E492: Not an editor command: It contains:
line 5:
E20: Mark not set
line 6:
E20: Mark not set
line 7:
E20: Mark not set
line 9:
E492: Not an editor command: support_functions.vim
contains functions that are called from some of the
line 10:
E492: Not an editor command: snippets. This file should be
sourced somewhere like your vimrc or the same
line 11:
E492: Not an editor command: place you do the rest of your
> from inside Vim, do ~/vimfiles/doc
This explanation is also a little "fuzzy" to me:
rails to learn more about Tim Pope’s Rails.vim plugin.
You can use surround, nerdtree” to learn more about the other bundled plugins as well. Rails.vim gives you commands such as :Rgenerate that calls script/generate, :Rake for rake tasks, :Rscript for other script/* inside your Rails project.
Is it all explained in the screencast?
Are there some good screencasts for how to develop rails apps using Textmate? Just bought the license.
Also considering Aptana Rad Rails for windows.
i was also keeping an eye on the screencast but i couldn't get the rspec boundle to work, for example the "it[tab]" does nothing but "it[this is a tab]"
i of course cloned your git repo and updated the submodules
i think it has something to do with the ruby-rspec snippet or some misconfiguration
i'll appreciate a lot your knowledge here, thanks!
'Can't open file /home/user/vimfilessnippetssupport_functions.vim'
How do i get rid of this??
did you do
#git submodule init
#git submodule update
after cloning?
just a quick question.
when I watch you using snippet, there is a line underneath cursor which looks like <++> and then when you ends up the first snippet, it seems to repeat the same snippet on the next line.
how do you do that ?
$ Error detected while processing /Users/ghoster/.vimrc:
line 261:
E484: Can't open file $HOMEPATHvimfilessnippetssupport_functions.vim
I looked at line 261 in the .vimrc file and it appears that it gets to this line due to the following line results in an error:
source ~/.vim/snippets/support_functions.vim
Now, I looked at my ~/.vim/snippets directory and it is empty, so the file support_functions.vim does not exist. Have I done anything wrong?
Any help would greatly appreciated.
See the link to the update post at the very top. Looks like you need to pull in the snippets submodule.