3

I'm struggling with using .vimrc to apply specific configurations based on the filetype. Following the autocmd FileType suggestion here, I have attempted to apply a configuration based on filetype. Here is what I have in my .vimrc:

autocmd FileType tex call Tex_config()
  function Tex_config()
    let g:LatexBox_viewer = 'skim'
    let g:LatexBox_latexmk_options = '-pvc'
    let g:tex_flavor = "latex"
    setlocal spell spelllang=en_ca
  endfunction

I can call the function Tex_config() with :debug Tex_config: Vim happily spets through the function. So, everything seems like it should work.

But, when I issue :set filetype=tex something strange happens: spell checking turns off. And when I issue :set filetype=foo spell checking turns on. Just the reverse of what I expect to happen from this configuration snippet!

Any assistance would be greatly appreciated. Here is the full vimrc (function at 44-50). Thanks.

Update: Another part of the puzzle: when I load a TeX file, preferences are read without a problem. The problem arises on :set filetype=tex.

1
  • Note, completely revised answer based on my working .vimrc file instead of crazy speculation :)
    – Caleb
    Apr 25, 2011 at 18:45

1 Answer 1

1

After comparing your .vimrc with mine it seems the primary difference is that all of my function commands end with a bang like this:

function! ExtPrefFunction()
   " Preferences here
endfunction
autocmd Filetype ext call ExtPrefFunction()

Honestly I don't know why they are that way, but mine work. Also you do this:

if &filetype == "ext"
    " Preferences here
endif

...but that only registers when you first open the file for editing, not any time the filetype indicator changes.

3
  • Thanks for your suggestion. I tried using a bang, and putting the autocmd line after the function, but it didn't work. Here's another part of the puzzle: when I load a TeX file, everything works swimmingly. It appears that it is the :set filetype=tex that doesn't pick up the filetype properly. Any other ideas? Apr 25, 2011 at 19:35
  • What does :set show as the value for filetype when you load a tex file automatically as opposed to setting the value yourself?
    – Caleb
    Apr 25, 2011 at 19:37
  • :set shows tex as the filetype, both when I load a tex file automatically, and when I set the filetype value myself. Apr 25, 2011 at 20:18

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .