Search code examples
vimpluginsindentationtext-editorvi

Vim plugin "auto-pairs" change automatic indent size?


I'm not sure if this is the right place to ask about this, but I figured it couldn't hurt to ask here. I am using a plugin called auto-close so that I don't have to close my own parentheses. It has a very nice feature that does the following:

Image

This is a great feature, but I don't like how far it indents for me. I have the following line in my .vimrc:

" for filetype "js", tab = insert 4 spaces, backspace will delete all 4
autocmd Filetype javascript setlocal expandtab softtabstop=4

In editing a javascript file, it automatically did an 8-space indentation instead of a 4-space indenation, as I've specified in my .vimrc. Can anybody help me figure out how I can make it automatically indent 4-space tabs instead of 8-space tabs? I can't find it in the documentation either. Thanks!


Solution

  • If you get shiftwidth=8, softtabstop=0, tabstop=8, that means that your autocmd FileType didn't take effect. You'd have to troubleshoot that.

    I would recommend putting any settings, mappings, and filetype-specific autocmds into ~/.vim/ftplugin/{filetype}_whatever.vim (or {filetype}/whatever.vim; cp. :help ftplugin-name) instead of defining lots of :autocmd FileType {filetype}; it's cleaner and scales better; requires that you have :filetype plugin on, though. Settings that override stuff in default filetype plugins should go into ~/.vim/after/ftplugin/{filetype}.vim instead. The change of indent settings would fit the latter, after directory location.