# Vim: space or tab in indenting?

**URL:** <https://www.ruby-forum.com/t/vim-space-or-tab-in-indenting/59689>\
**Category:** Rails\
**Created:** [May 5, 2006, 2:30pm UTC](https://www.ruby-forum.com/t/vim-space-or-tab-in-indenting/59689 "2006-05-05T14:30:17Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![mutejute](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/9de053/32.png) [@mutejute](https://www.ruby-forum.com/u/mutejute)\
**Post date:** [May 5, 2006, 2:30pm UTC](https://www.ruby-forum.com/t/vim-space-or-tab-in-indenting/59689/1 "2006-05-05T14:30:17Z")

</div>

this is semi-off topic but still related to ror.

i had a problem with testing my depot program (which i follow the  
tutorial in agile web development book). it took me many hours to solved  
the problem. all the while i thought i was using spaces inside the  
test/fixtures/products.yml

programmer\_book:  
id: 1  
title: Pragmatic Programmer  
description: Best book for the programmer  
image\_url: [http://localhost:3000/images/pp.jpg](http://localhost:3000/images/pp.jpg)  
price: 29.95  
date\_available: 2006-05-01 00:00:00  
^^ ^^^^

the culprit is there were tabs in my code, before the key (id,  
title,…). replaced it with space and now my program/testing worked.

im using vim and i was thinking of changing my preferences on  
tabbing/indenting. instead of tabs, it will insert spaces. but i want to  
know if there are any implications on using space instead of tabs in the  
code. thanks.

---

<div class="post-metadata">

**Author:** ![mutejute](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/9de053/32.png) [@mutejute](https://www.ruby-forum.com/u/mutejute)\
**Post date:** [May 5, 2006, 2:36pm UTC](https://www.ruby-forum.com/t/vim-space-or-tab-in-indenting/59689/2 "2006-05-05T14:36:14Z")

</div>

Hi

seems that (although I wasn’t aware of that) tab are prohibited under  
YAML  
(see [YAML Ain't Markup Language](http://www.yaml.org/faq.html))

cheers

---

<div class="post-metadata">

**Author:** ![mutejute](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/9de053/32.png) [@mutejute](https://www.ruby-forum.com/u/mutejute)\
**Post date:** [May 5, 2006, 3:15pm UTC](https://www.ruby-forum.com/t/vim-space-or-tab-in-indenting/59689/3 "2006-05-05T15:15:55Z")

</div>

malamute jute wrote:

> im using vim and i was thinking of changing my preferences on  
> tabbing/indenting. instead of tabs, it will insert spaces. but i want to  
> know if there are any implications on using space instead of tabs in the  
> code. thanks.

In YAML, as has already been pointed out, tabs are banned. In code?  
That’s a religious question, but I think the tendency among rubyists is  
towards spaces over tabs, because you can’t guarantee the appearance of  
indentation with tabs.

There is (as I understand it) currently an issue with RMagick on Windows  
related to tabs in code, but that’s definitely a bug somewhere. They  
should be interchangable.

---

<div class="post-metadata">

**Author:** ![mutejute](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/9de053/32.png) [@mutejute](https://www.ruby-forum.com/u/mutejute)\
**Post date:** [May 5, 2006, 3:28pm UTC](https://www.ruby-forum.com/t/vim-space-or-tab-in-indenting/59689/4 "2006-05-05T15:28:09Z")

</div>

On May 5, 2006, at 9:13 AM, Alex Y. wrote:

> There is (as I understand it) currently an issue with RMagick on  
> Windows related to tabs in code, but that’s definitely a bug  
> somewhere. They should be interchangable.

You probably won’t run into this dealing with Ruby, but if you write  
old fashioned Makefiles, they _require_ tabs. And if you use spaces  
in your make rules, it gives a rather cryptic error message…yeah,  
that one took me a while to track down. grrr

Other than that, I prefer spaces … especially if swapping code with  
others! 🙂

-Derrick

---

<div class="post-metadata">

**Author:** ![mutejute](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/9de053/32.png) [@mutejute](https://www.ruby-forum.com/u/mutejute)\
**Post date:** [May 5, 2006, 4:26pm UTC](https://www.ruby-forum.com/t/vim-space-or-tab-in-indenting/59689/5 "2006-05-05T16:26:57Z")

</div>

On Fri, 5 May 2006, malamute jute wrote:

> im using vim and i was thinking of changing my preferences on  
> tabbing/indenting. instead of tabs, it will insert spaces. but i want to  
> know if there are any implications on using space instead of tabs in the  
> code. thanks.

The Ruby and Rails folks seem to prefer spaces, with two spaces per  
indentation level. The Rails website actually says this is what you  
should use if you want to contribute code.

Myself, I prefer tabs, but I suspect I’ll move to what the community  
uses  
because it isn’t worth struggling with.

I use vim all the time as well, and it’s default bindings with the tabs  
and autoindent have been making me insane, and I probably will finally  
go  
in and shut them off.

–  
Louis Erickson - removed\_email\_address@domain.invalid - [Lou's Home Page!](http://www.rdwarf.com/~wwonko/)

Hartley’s Second Law:  
Never sleep with anyone crazier than yourself.

---

<div class="post-metadata">

**Author:** ![mutejute](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/9de053/32.png) [@mutejute](https://www.ruby-forum.com/u/mutejute)\
**Post date:** [May 5, 2006, 5:59pm UTC](https://www.ruby-forum.com/t/vim-space-or-tab-in-indenting/59689/6 "2006-05-05T17:59:15Z")

</div>

So what is the main reason why the rails community uses spaces instead  
of  
tabs? I’ve always used tabs because it offers control of how much white  
space is shown to the current person editing the file, not who  
originally  
wrote it. My coworker likes to have 8 char wide tabs, I personally hate  
that and like to edit with 4 char wide tabs and maybe others like 2.

Rob

---

<div class="post-metadata">

**Author:** ![mutejute](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/9de053/32.png) [@mutejute](https://www.ruby-forum.com/u/mutejute)\
**Post date:** [May 5, 2006, 6:50pm UTC](https://www.ruby-forum.com/t/vim-space-or-tab-in-indenting/59689/7 "2006-05-05T18:50:56Z")

</div>

Rob M. wrote:

> So what is the main reason why the rails community uses spaces instead  
> of  
> tabs? I’ve always used tabs because it offers control of how much white  
> space is shown to the current person editing the file, not who  
> originally  
> wrote it. My coworker likes to have 8 char wide tabs, I personally hate  
> that and like to edit with 4 char wide tabs and maybe others like 2.
> 
> Rob

It keeps code looking nice

2 space tabs:

SomeModel.create :value =\> 1,  
:foo =\> 123,  
:bar =\> ‘asdf’

now convert that to 4 space tabs and you have something like:

```
SomeModel.create :value => 1,
                                  :foo => 123,
                                  :bar => 'asdf'
```

---

<div class="post-metadata">

**Author:** ![mutejute](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/9de053/32.png) [@mutejute](https://www.ruby-forum.com/u/mutejute)\
**Post date:** [May 5, 2006, 5:50pm UTC](https://www.ruby-forum.com/t/vim-space-or-tab-in-indenting/59689/8 "2006-05-05T17:50:09Z")

</div>

On May 5, 2006, at 7:10 AM, Louis Erickson wrote:

> indentation level. The Rails website actually says this is what you  
> in and shut them off.
> 
> –  
> Louis Erickson - removed\_email\_address@domain.invalid - [Lou's Home Page!](http://www.rdwarf.com/~wwonko/)

FOr ruby code I always use spaces. It is what most of the ruby code  
you will find uses. And a really good reason not to use tabs is that  
when you use tabs, you can no longer paster your code into irb to  
play with it for testing. Irb will see each tab as a command  
completion requests and flip out on you. Since irb is such an  
indespensible tool for ruby code, this fact alone warrants only ever  
using spaces.

Cheers-  
-Ezra
