0

I am trying to set some tab indent configurations in Vim. Unfortunately I can't get it working.

In my last line I use

u FileType javascript set tabstop=4

in the hope of having the tab width set to 4.

But when I open a .js file and press tab it inserts only 2 spaces. I tried to comment out the other whitespace stuff without success.

Here is also my full vimrc: https://gist.github.com/919909

How do I set the tabs and so on for Javascript files, and why does the above not work?

Update

The problem seems to be somewhere else as when editing new Javascript files it works as expected. It only seems to behave differently on the Javascript files in my Rails project. How could that be? I have a Rails.vim plugin installed, could that be the cause?

medihack
  • 16,045
  • 21
  • 90
  • 134
  • see also http://stackoverflow.com/questions/234564/tab-key-4-spaces-and-auto-indent-after-curly-braces-in-vim – Ken Apr 14 '11 at 17:03

2 Answers2

2

'tabstop' is the number of spaces a tab character in the file counts for. The number of spaces of an indentation level is set with the 'shitfwidth' option, and the number of spaces that a tab counts for when doing edit operations is set with 'softtabstop'. It's a little complicated, but if you set both 'shitfwidth' and 'softtabstop' to the same value, you'll probably get what you want. You can keep 'tabstop' at the default value.

If you are one of those that like spaces all the time and not tabs, you these settings will probably suit you.

The Rails plugin is probably setting some of these leading to the different behavior you're experiencing.

Community
  • 1
  • 1
R. Martinho Fernandes
  • 228,013
  • 71
  • 433
  • 510
1

Ok, the root of the problem seems to be in Rails.vim (see https://github.com/tpope/vim-rails/pull/78)

But there is also this easy solution:

autocmd User Rails/**/*.js set tabstop=4
medihack
  • 16,045
  • 21
  • 90
  • 134