2

TL;DR: How do I permanently and persistently :set syntax=context for *.tex files?


I've been using vim for a LaTeX project, with monokai-tasty as the colour scheme.

The default syntax highlighting seems to be TeX Highlighting

:set syntax=tex

I personally prefer ConTeXt Highlighting

:set syntax=context

but cannot figure out how to make it stick for all *.tex buffers, or between sessions.

I've tried several ways of getting this to work, mostly through vimrc, though none of them have. Most recently I created ~/.vim/ftdetect/tex.vim containing

autocmd BufNewFile,BufRead *.tex set syntax=context

My vimrc can be seen here, in case there are any obvious collisions with what I'm trying to do there.


Not sure if I've given enough information. I am, of course, happy to add any more if it's not enough to be helpful.

2 Answers 2

3

I think what you are looking for is the variable g:tex_flavor. Put this in your vimrc file:

let g:tex_flavor = 'context'

For more information, see :help g:tex_flavor.

7
  • Should that be in ~/.vim/ftdetect/tex.vim or in vimrc? Should it follow something like autocmd BufNewFile,BufRead *.tex let g:tex_flavor = 'context'.
    – BitFlow
    Jul 2, 2019 at 13:22
  • This seems to work when loading a file but upon rerunning :source ~/.vimrc it reverts to the same result as :set syntax=tex so perhaps it isn't working at all?
    – BitFlow
    Jul 2, 2019 at 16:43
  • As I wrote in the answer: "Put this in your vimrc file". Jul 3, 2019 at 14:02
  • To clarify my second comment, which you seem to have skipped over: having tried that, it isn’t working as I would expect or hope.
    – BitFlow
    Jul 3, 2019 at 14:19
  • 1
    You should not need to do :source ~/.vimrc, since this is done when Vim starts. The file should be correctly highlighted when you open it, not when you source your vimrc file. Jul 7, 2019 at 13:50
1

If you just want to set the syntax always to context, just put this in your vimrc:

autocmd BufReadPost *.tex set syntax=context

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.