Ian Sheridan's Homepage

Overriding Indentation Settings for vim-rails

I have been banging my head against the wall trying to figure out how to override the hard coded indentation settings for vim-rails. I use MacVIM and GVIM on my work and home computers. I use the Janus project to set up my G/MacVIM installs. Janus uses vim-rails. And I want to use tabs for my indentation instead of 2 spaces.

First off, I do understand that it is a strong convention to use 2 spaces for indentation when programming Ruby but I am a TABS indent-er always have been and as far as I am concerned always will be. I am not going to discuss it heavily here other then to say that you should be consistent in using one or the other. Readability is paramount when collaborating with another programmer.

So, how did I finally figure it out? Well thanks to some JS guys I found this command:

autocmd User Rails/**/*.js set sw=4

That sets the tab indentation for JS files to 4 spaces. But I want all files underneath my rails projects to use tab indentation at 3 spaces. So using autocmd I now have a ~/.gvimrc.local file (a janus convention, if you are not using janus just edit ~/.gvimrc) with the following in it:

set tabstop=3
set shiftwidth=3
set softtabstop=3
set noexpandtab
autocmd User Rails/**/* set tabstop=3
autocmd User Rails/**/* set shiftwidth=3
autocmd User Rails/**/* set softtabstop=3
autocmd User Rails/**/* set noexpandtab

This ensures that all the files under a Rails project uses TABs that are 3 spaces long. DONE. I am yet again a happy camper.

UPDATE: Found some issues for the rais-vim project that proved interesting.

https://github.com/tpope/vim-rails/issues/79 - a future release will not have the indentation override. https://github.com/tpope/vim-rails/pull/78 - where I found the override that I use here.

© 2012 Ian Sheridan, all rights reserved.