VIM-ftplugin似乎不起作用

问题描述 投票:4回答:1

我正在使用spf13的vim发行版https://github.com/spf13/spf13-vim。我一直试图为.js文件使用2个空格而不是4个空格,因此我在js.vim中创建了一个~/.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
vim ftplugin
1个回答
19
投票

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根本没有定义默认的制表符宽度。

© www.soinside.com 2019 - 2024. All rights reserved.