If syntax on comes before filetype plugin on, after/syntax/tex.vim does not know about which packages are included in the tex file and therefore does not show any syntax highlighting added by vimtex for python code and other. Variable/entry in dictionary b:vimtex.packages.pythontex does not yet exist.

If we change the order in the vimrc to (e.g. vim-sensible has this order)
filetype plugin on
syntax on
we get the additional syntax highlighting of python code:

I came across this reusing $VIMRUNTIME/defaults.vim in my vimrc with
source $VIMRUNTIME/defaults.vim
For example, re-using defaults.vim is also suggested in $VIMRUNTIME/vimrc_example.vim.
Part of defaults.vim at its current state
" Switch syntax highlighting on when the terminal has colors or when using the
" GUI (which always has colors).
if &t_Co > 2 || has("gui_running")
" Revert with ":syntax off".
syntax on
" I like highlighting strings inside C comments.
" Revert with ":unlet c_comment_strings".
let c_comment_strings=1
endif
" Only do this part when Vim was compiled with the +eval feature.
if 1
" Enable file type detection.
" Use the default filetype settings, so that mail gets 'tw' set to 72,
" 'cindent' is on in C files, etc.
" Also load indent files, to automatically do language-dependent indenting.
" Revert with ":filetype off".
filetype plugin indent on
"...
endif
How should vimtex
1) document this in the docs,
2) handle this, and
3) respond with a message if the "wrong" order is detected.
Possibilities:
1) require or recommend specific order
2) if "wrong" order, either enable all pkg syntax features or none; or reload syntax after filetype if syntax on (possible?)
3) Message: syntax is sourced before filetype, ie. syntax does not enable package specific highlighting or all syntax highlighting groups are added regardless of what packages are actually used (possible slower syntax highlighting)
Good questions. Personally, I find it makes much sense to first source the filetype plugins, and I believe all/most plugin managers apply these lines in this order.
I propose the following update:
Initialize the g:vimtex_syntax_enable option similar to other options.
If this option is not defined, then give a warning to explain the possible wrong order.
What do you think? I'm pushing this now, but I'll update further when we agree on a good solution.
What do you think?
Yes, I like it.
However, I would mention in the docs if someone has no vimrc, defaults.vim will be sourced which has the "wrong" order. Therefore, I would recommend in general to explicitly set the order in vimrc.
If someone likes other parts of defaults.vim, sourcing defaults.vim afterwards is fine:
filetype plugin on
syntax on
source defaults.vim
Noting that vim-plug and maybe vim-sensible enables the features in the right order is good.
A quick check for some other popular plugin manager:
1) vundle
CONTRIBUTING.md suggests the wrong order for the minivimrc.
2) dein
https://github.com/Shougo/dein.vim#unixlinux-or-mac-os-x suggests the right order
This prints the warning for any syntax file that loads the tex syntax without using vimtex. For example, https://github.com/plasticboy/vim-markdown/blob/a15334cac67237835e62c9dd1470f6162769779f/syntax/markdown.vim#L147.
Is the proper workaround to make sure g:vimtex_syntax_enabled exists? It is not documented.
I am also seeing this warning when opening vimwiki files
This prints the warning for any syntax file that loads the _tex_ syntax without using vimtex. For example, https://github.com/plasticboy/vim-markdown/blob/a15334cac67237835e62c9dd1470f6162769779f/syntax/markdown.vim#L147.
Is the proper workaround to make sure
g:vimtex_syntax_enabledexists? It is not documented.
setting g:vimtex_syntax_enabled = 0 silences the warning messages for the time being, especially important for vimwiki
I admit that I did not anticipate that some useafter/syntax/tex.vim from vimtex as a standalone syntax addition to the one provided by vim itself.
I agree that the file could be written to make it possible to use it this way. Maybe not all features are available but those which do not need the filetype plugin should work.
@yigitsever @Coleej @smancill Sorry about the regression, guys! I'm fixing things asap/now.
I think my latest update should fix things so they work similarly as before. The warning will now be issued by the filetype plugin, not by the syntax plugin. Thus the syntax improvements may still be safely loaded e.g. in vimwiki or markdown, even though the filetype plugin is not loaded.
"syntax on" seems to be applied before "filetype plugin on". This is suboptimal, because some syntax features require an initialized state. Please see ":help vimtex_syntax_filetype".
I use vim-plug, as kiryph has pointed out, vim-plug handles the order automatically. But I just ran into the warning above.
I set g:vimtex_syntax_enabled = 0 in my vimrc to disable after/tex.vim, but still got warning.
Then I added the following in the head of my vimrc, which didn't work.
filetype plugin on
syntax on
I use NeoVim and it doesn't have defaults.vim in the $VIMRUNTIME. Any help, pls
P.S. My vimrc
call plug#begin('~/.vim/plugged')
Plug 'lervag/vimtex', {'for': 'tex'}
call plug#end()
let g:vimtex_syntax_enabled = 1
Are you using the latest version of vimtex? If you are, and if you have this problem, then please, open a new issue where you describe how to reproduce it. Please respond to the issue template and include a minimal LaTeX sample and a minimal vimrc file.
Yes, I just updated vimtex and ran into this issue.
I will debug my vimrc and to find what caused this issue. If not found, I will open an issue here. Thanks for your quick response.
I get this issue with an empty ~/.vimrc (except execute pathogen#infect()) and only vimtex in ~/.vim/bundle.
It seems to be some conflict with Pathogen.
@Geremia If you have an empty vimrc, syntax should not be enabled. Afaik, pathogen does not do this.
Yes, please open a new issue and describe how to reproduce. If I can reproduce it, then I can fix it. :)
I am sorry, I accidentially deleted my post when I noticed an error. I am not using :next to switch between the buffers, but :buffer N.
My issue is that opening two tex-files and switching between the buffers prompts the warning message. The first time I open each buffer I do not get the message, only when switching between them. And only when the buffer is not previously loaded.
I will test that this is not due to my own stupidity, and then post a proper issue if needed.
I still can't reproduce (even with a minimal vimrc file), so please post a proper issue if you want more help.
Ok, I have now tried it with a minimal vimrc and I do not get the error message! Really sorry for taking up your time. Btw, thanks for this great plugin!
No problem! Feel free to open a new issue to describe what is needed from your personal config to reproduce the problem. I would not be surprised to find more bugs.
Btw, thanks for this great plugin!
Thanks! :)
This happens when we have let g:tex_flavor = "latex" in vimrc. The autoload/dist/ft.vim gets executed before vimtex. How can we have this error gone in this case?
@wookayin Please open a new issue and explain how to reproduce. I also have let g:tex_flavor = "latex" in my vimrc file, and I don't have this problem. So obviously it is more involved than that. If you adhere to the issue template, you should be able to create an issue report that pinpoints the necessary files/settings/steps to reproduce, in which case I should be able to fix it.
Most helpful comment
I think my latest update should fix things so they work similarly as before. The warning will now be issued by the filetype plugin, not by the syntax plugin. Thus the syntax improvements may still be safely loaded e.g. in vimwiki or markdown, even though the filetype plugin is not loaded.