Saari Development

Ali Rizvi's Technical Blog as a Professional Software Development Engineer

Vim: Auto indenting based on filetype

with one comment

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.

Cheers!

Advertisements

Written by imsaar

January 27, 2009 at 1:34 am

Posted in editor, vim

One Response

Subscribe to comments with RSS.

  1. I know this is an old post but it is exactly what I was looking for. I too ran into the same problem. I would add to my .vimrc file, set smartindent. Then execute vim. Indentation just didn’t work right! Adding your line made it all work like the magic that it is.

    Thanks!

    Jeremy Cowgar

    April 11, 2011 at 6:43 pm


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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s

%d bloggers like this: