Vim tabs for Ruby

I’ve been annoyed time and time again by size-8 tabstops, mostly in when vim autoindents. In some languages, I’m happy to have ai on, but it’s frustrating to occasionally find a huge tab in my indents!

The two things you need to set are tabstop and shiftwidth.

:set tabstop=2
:set shiftwidth=2

Now, vim does its autoindenting right.

There’s also :set softtabstop .. but I can’t really tell what it does. I figured these things out from this place, but it doesn’t quite seem to be right, as my softtabstop probably isn’t set to 2, but hitting tab only indents me 2 spaces.

I also ran across the ability to just type :set and find out what things you’ve set up in vim at the moment; that’s kind of nice. It looks like it doesn’t deal with a lot of defaults, as I cannot find “softtabstop” in there, which is probably set, but not by any manual setting.

So, I’ve typed these in.. how do I get them to stick forever? I’m going to put them in my vimrc. On a unix system, this would be in ~/.vimrc, and on Windows, this should be in $HOME/_vimrc or in $VIMRUNTIME/_vimrc. Your HOME one will override your VIMRUNTIME one (the vimruntime one is probably somewhere like C:\Program Files (x86)\Vim7x\_vimrc).

You can go into them and just drop your set commands inside to make for nice indentation.

Leave a Reply

Your email address will not be published.