VIM - ftplugin似乎不起作用

Irv*_*ato 4 vim ftplugin

我正在使用spf13的vim发行版https://github.com/spf13/spf13-vim.我一直在尝试使用2个空格而不是4个空格用于.js文件,因此我创建了一个js.vimin ~/.vim/ftplugin.我做错了吗?

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
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.你实际上正在与那个该死的发行版进行斗争,以便按照想要的方式设置你的环境,因为互联网上的一些智能手机决定他比你更了解你想要/需要什么.


阅读文档,不要使用发行版.

  • +1.可能听起来很难相信vim分布被认为是有害的,但Vim是一个漫长的旅程.大多数发行版扰乱了这一自然之旅.@romainl正在赐予这种智慧,只有多年的Vim使用才会出现.祝你旅途愉快 (8认同)
  • @PeterRincker谢谢您的反馈...我将尽力与旅程保持一致。我想我现在将从全新安装开始。:) (2认同)