I made up keybindings to compile tex file in Vim but sometimes it doesn't work because the file is identified as a plaintex file. I'd like to understand the difference. I have also noticed that this always happens when creating a new file with vim test.tex.

1 Answer 1


Take a look at this question and its answers on TeX.SX to understand the difference between TeX and plainTeX.

You can make a single keybinding working for tex and plaintex or you can force Vim to interpret each .tex file as a tex file. According to :help tex_flavor,

If the first line of a *.tex file has the form
then this determined the file type:  plaintex (for plain TeX), context (for
ConTeXt), or tex (for LaTeX).  Otherwise, the file is searched for keywords to
choose context or tex.  If no keywords are found, it defaults to plaintex.
You can change the default by defining the variable g:tex_flavor to the format
(not the file type) you use most.  Use one of these:
        let g:tex_flavor = "plain"
        let g:tex_flavor = "context"
        let g:tex_flavor = "latex"
Currently no other formats are recognized.

:let g:tex_flavor = "latex" in your .vimrc will do the work.

  • 1
    There’s also a bit of guessing done; e.g., if you have \begin{document} or something similar i think will generally assume latex
    – D. Ben Knoble
    Mar 4, 2020 at 13:59
  • 1
    @D.BenKnoble The biggest issue I see with the guessing part is when you start a new .tex file from scratch. You'll get a default that's not likely useful and will have to mess with :set ft to update it. +1 to setting tex_flavor in vimrc.
    – filbranden
    Mar 4, 2020 at 15:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy