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?
set shiftwidth=2 " Use indents of 2 spaces
set tabstop=2 " An indentation every two columns
set softtabstop=2 " Use two spaces while editing
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.