I open .tex
files with Vim, but some files are recognized as filetype=plaintex
and others as filetype=tex
. Why is this? What is the trigger that recognizes the file as tex, which has the highlighting I want?
Vim and TeX filetypes: plaintex vs. tex
latextexvim
Best Answer
Why are some
.tex
files opened in Vim asfiletype=plaintex
and others asfiletype=tex
? Since the same extension,.tex
in this case, is used for multiple filetypes, "Vim tries to guess what kind of file it is" according to the Vim filetype-overrule documentation.The ft-tex-plugin section of the Vim filetype documentation lists the rules used by Vim (versions 7 and higher) to determine which filetype to use for
.tex
files:%&<format>
where<format>
can beplain
,context
, orlatex
, then the filetype is set to plain TeX, ConTeXt, or LaTeX, respectively.context
(ConTeXt) ortex
(LaTeX).plaintex
(plain TeX).The last rule is important. If you create an empty
.tex
file using a command liketouch myfile.tex
, then when you open it in Vim the filetype will default toplaintex
, since the file is blank.You can change the default behavior by setting the global variable
tex_flavor
in your.vimrc
:let g:tex_flavor = "plain"
let g:tex_flavor = "context"
let g:tex_flavor = "latex"