6

I'm using spf13's vim distribution https://github.com/spf13/spf13-vim. I have been trying to use 2 spaces instead of 4 spaces for .js files, for that reason I have created a js.vim in ~/.vim/ftplugin. Am I doing it wrong?

js.vim

    set shiftwidth=2                " Use indents of 2 spaces
    set tabstop=2                   " An indentation every two columns
    set softtabstop=2               " Use two spaces while editing

1 Answers1

23

The naming convention for ftplugin filenames is:

{filetype}.vim

In your case, the filetype is javascript, not js, so it would be:

~/.vim/ftplugin/javascript.vim

or, better:

~/.vim/after/ftplugin/javascript.vim

Also, you must use setlocal instead of set to prevent your options from leaking to other buffers:

setlocal shiftwidth=2
setlocal tabstop=2
setlocal softtabstop=2

Note that the default JavaScript ftplugin doesn't define a default tabwidth at all.

romainl
  • 186,200
  • 21
  • 280
  • 313
  • 8
    +1. It may sound hard to believe that vim distributions are considered harmful however Vim is is a long journey. Most distributions disrupt this natural journey. @romainl is giving this wisdom that only comes with years of Vim usage. I wish you well on your journey – Peter Rincker Jul 05 '14 at 16:21
  • 2
    @PeterRincker thank you for the feed back... i will try to go along with the journey. I think I'm going to start from a clean install right now. :) – Irvin Denzel Torcuato Jul 05 '14 at 18:55