Reputation: 115
I am trying to configure my vimrc so that tabs are 2 spaces when editing tex documents.
In my vimrc file, I have
au BufNewFile,BufRead *.py:
\ set tabstop=4
\ set softtabstop=4
\ set shiftwidth=4
\ set textwidth=79
\ set expandtab
\ set autoindent
\ set fileformat=unix
au BufNewFile,BufRead *.js, *.html, *.css, *.tex:
\ set tabstop=2
\ set softtabstop=2
\ set shiftwidth=2
However, when I edit a document in vim, it ignores the tabstop. Tabs are much longer than 2 spaces. Vim does not throw out any errors. I do not understand why it ignores the tabstop=2 line when I am editing a tex document. I have to run :set tabstop=2 while editing.
Can anyone see how my configuration file is wrong?
In case this is relevant, I am using the vimtex plugin.
Thank you.
Upvotes: 0
Views: 1027
Reputation: 172768
:help autocmd-patterns
.:
colon after the pattern.:set
, better use :setlocal
, otherwise the indent settings will be inherited to any new buffer that is created from within one of those.:set
command into one.au BufNewFile,BufRead *.js,*.html,*.css,*.tex
\ setlocal tabstop=2 softtabstop=2 shiftwidth=2
Instead of the :autocmd
, I would prefer to put this into ~/.vim/after/ftplugin/{filetype}.vim
. (This requires that you have :filetype plugin on
; use of the after directory allows you to override any default filetype settings done by $VIMRUNTIME/ftplugin/{filetype}.vim
.) The small downside is that you have to duplicate the :setlocal
commands for every filetype, but to me, the fact that you would like to have the same indent settings for those languages is accidental, and there's no connection between those configurations.
Alternatively, you could define an :autocmd FileType {filetype} ...
directly in your ~/.vimrc
. With this, you at least wouldn't duplicate the built-in filetype detection and the file glob patterns used by it:
au FileType javascript,html,css,tex
\ setlocal tabstop=2 softtabstop=2 shiftwidth=2
Upvotes: 2