Vim: Auto indenting based on filetype

I had two different behaviors on my windows and linux machine when I used Vim to edit my ruby files.

I liked the auto-indent behavior I had on my windows machine but I did not know how to make it happen on my other linux machine.

I finally invested sometime to find out the difference between the two:

At first I thought I was simply missing

set autoindent

but I verified that I had that in both of my vimrc files.

The difference was that on my windows machine I was using the vimrc_example file which came with this line:

" load indent files, to automatically do language-dependent indenting.
filetype plugin indent on

This did the trick and I am so happy now.

Now when I start an if block and hit enter the second line starts with the appropriate indentation and when I type end the editor automatically indents it to the previous indentation level of the appropriate block of code.


One Response
  1. April 11, 2011