Типы файлов vim и TeX: открытый текст против текстовых

6530
Stefano Borini

Я открываю .texфайлы с помощью Vim, но некоторые файлы распознаются как, filetype=plaintexа другие как filetype=tex. Почему это? Что такое триггер, который распознает файл как tex, который имеет нужную подсветку?

20

3 ответа на вопрос

20
Matthew Rankin

Why are some .tex files opened in Vim as filetype=plaintex and others as filetype=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:

  1. If the first line of the file is %&<format> where <format> can be plaintex, context, or tex, then the filetype is set to plain TeX, ConTeXt, or LaTeX, respectively.
  2. If there is no format designator command on the first line, then Vim searches the file for keywords to determine if the filetype should be set to context (ConTeXt) or tex (LaTeX).
  3. If no keywords are found, the filetype is set to plaintex (plain TeX).

The last rule is important. If you create an empty .tex file using a command like touch myfile.tex, then when you open it in Vim the filetype will default to plaintex, 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"
12
frabjous

Вы используете плагин LaTeX-suite? Если так, то вы, вероятно, хотите

let g:tex_flavor='latex'

в вашем .vimrc.

Это не имеет ничего общего с плагином LaTeX-suite. См. Ответ Мэтью Ранкина или [`: h ft-tex-plugin`] (http://vimhelp.appspot.com/filetype.txt.html#ft-tex-plugin). Hotschke 5 лет назад 0
3
RedGrittyBrick

Больше, чем я когда-либо хотел знать об этом предмете: http://vimdoc.sourceforge.net/htmldoc/filetype.html

Чтобы отключить один из типов файлов, добавьте строку в файл filetype, см. | Remove-filetype |.