Although gabkdlly's link answers your question, I'll post some explanation on why vim is behaving the way it behaves.
Normally, vim does filetype detection based on file extension. The .tex
extension is shared by LaTeX, ConTeXt, plain TeX, and ePlain; so a simple filetype detection based on extension does not work. To circumvent this, vim checks for the file contents to see what type of a file it is: if the file contains a \begin{...}
most likely it is a LaTeX file, if it contains \start...
most likely it is a ConTeXt file, otherwise vim cannot be sure and it defaults to g:tex_flavor
. The default value of g:tex_flavor
is plain
.
When you open a new .tex
file, no keywords are found, so vim assumes that it is a plaintex
file. To default to other formats, use one of the following:
let g:tex_flavor = "plain"
let g:tex_flavor = "context"
let g:tex_flavor = "latex"
Note that some files might be misrecognized by the simplistic algorithm used by vim. If you want to ensure that a file is detected correctly, set filetype in a vim modeline:
% vim: ft=plaintex " For plain
% vim: ft=context " For context
% vim: ft=tex " For LaTeX
filetype plugin on
in your~/.vimrc
file. This should make it work for every*.tex
file. Not sure about toggling it on and off