Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VIM - ftplugin doesn't seem to work

Tags:

vim

ftplugin

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
like image 794
Irvin Denzel Torcuato Avatar asked Jul 05 '14 13:07

Irvin Denzel Torcuato


1 Answers

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.

like image 53
romainl Avatar answered Oct 12 '22 01:10

romainl