我正在使用spf13的vim发行版https://github.com/spf13/spf13-vim.我一直在尝试使用2个空格而不是4个空格用于.js文件,因此我创建了一个js.vimin ~/.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
Run Code Online (Sandbox Code Playgroud)
rom*_*inl 18
尽管您使用的愚蠢分发可能会或可能不会破坏标准的ftplugin机制(谁知道?),您应该为您的文件命名:
{filetype}.vim
Run Code Online (Sandbox Code Playgroud)
在您的情况下,文件类型javascript不是js,因此将是:
~/.vim/ftplugin/javascript.vim
Run Code Online (Sandbox Code Playgroud)
或更好:
~/.vim/after/ftplugin/javascript.vim
Run Code Online (Sandbox Code Playgroud)
此外,您必须使用setlocal而不是set防止您的选项泄漏到其他缓冲区,所以......
setlocal shiftwidth=2
setlocal tabstop=2
setlocal softtabstop=2
Run Code Online (Sandbox Code Playgroud)
请注意,默认的JavaScript ftplugin 根本没有定义默认的tabwidth.你实际上正在与那个该死的发行版进行斗争,以便按照你想要的方式设置你的环境,因为互联网上的一些智能手机决定他比你更了解你想要/需要什么.
阅读文档,不要使用发行版.