Context
I have my .vimrc
automatically being sourced with:
autocmd! BufWritePost ~/.vimrc source ~/.vimrc
I also set defaults for spacing:
set tabstop=2 softtabstop=2 shiftwidth=2 expandtab
Later on, I use the FileType
event to override the spacing default above with filetype-specific spacing:
" Syntax of these languages is fussy over tabs & spaces¬
autocmd FileType make setlocal ts=8 sts=8 sw=8 noexpandtab¬
autocmd FileType yaml setlocal ts=2 sts=2 sw=2 expandtab¬
" Customisations based on house-style (arbitrary)
autocmd FileType sh setlocal ts=4 sts=4 sw=4 expandtab
autocmd FileType vim setlocal ts=4 sts=4 sw=4 expandtab
Problem
The problem I am having is that sourcing my .vimrc
will set the default values, but will not trigger the FileType
event. This means that when I do a :write
to my .vimrc
while editting a file with filetype-specific spacing, the filetype-specific spacings get overridden by the defaults!
UPDATE: As pointed out by Ingo, the issue only arises in .vimrc
and does not occur in any other files.
Example
As an example, when I am working on my .vimrc
, initially the file-specific spacing (ts=4 sts=4 sw=4 expandtab
) is enabled, but after I make some arbitrary change in my .vimrc
, the default spacing (tabstop=2 softtabstop=2 shiftwidth=2 expandtab
) is loaded but my file-specific spacing is NOT loaded (since the FileType
event was not triggered by a write to my .vimrc
) leaving me with the default spacing!
My question(s)
How can I override the default spacing with filetype specific spacings and preserve these even when auto-sourcing .vimrc
?
If possible, I would like to accomplish this without getting rid of the autocmd's. Is that possible?
My hunch is that I should somehow manually trigger the FileType event when sourcing .vimrc
Can this be done and is this the recommended approach?
.vimrc
! Your suggestion worked, but it needed to be lower in the.vimrc
file that the global default declaration to work. – Pedro Cattori Aug 19 '14 at 07:54