我正在使用spf13的vim发行版https://github.com/spf13/spf13-vim。我一直试图为.js
文件使用2个空格而不是4个空格,因此我在js.vim
中创建了一个~/.vim/ftplugin
。我做错了吗?
set shiftwidth=2 " Use indents of 2 spaces
set tabstop=2 " An indentation every two columns
set softtabstop=2 " Use two spaces while editing
ftplugin文件名的命名约定是:
{filetype}.vim
在您的情况下,文件类型为javascript
,而不是js
,因此它将是:
~/.vim/ftplugin/javascript.vim
或者更好:
~/.vim/after/ftplugin/javascript.vim
此外,您必须使用setlocal
而不是set
,以防止您的选项泄漏到其他缓冲区:
setlocal shiftwidth=2
setlocal tabstop=2
setlocal softtabstop=2
请注意,默认的JavaScript ftplugin根本没有定义默认的制表符宽度。