1

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.

migrated from superuser.com Jul 1 at 19:54

This question came from our site for computer enthusiasts and power users.

0

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.

  • 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 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 at 16:43
  • As I wrote in the answer: "Put this in your vimrc file". – Karl Yngve Lervåg Jul 3 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 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. – Karl Yngve Lervåg Jul 7 at 13:50

Your Answer

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

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