KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I am trying to get Vim to syntax highlight any file that ends with extension .Rtex in the following way: All top level text is highlighted as TeX Exception: any text enclosed in \begin{python}...\end{python} is highlighted as Python I am able to achieve each of these criteria individually, but unable to achieve both simultaneously. I think that somehow the TeX highlighting overrides my Python-highlighted regions, or prevents them from taking effect, and I am stuck trying to figure out how. First step: edit .vimrc to give files with extension .Rtex the filetype rtex : au BufRead *.Rtex setf rtex Second step: create ~/.vim/syntax/rtex.vim . It is the contents of this file that will determine how to highlight .Rtex files. Third step: enable general top-level TeX highlighting, by making rtex.vim look like this: runtime! syntax/tex.vim If I now open a .Rtex file, the entire file is highlighted as TeX, including any text within \begin{python}...\end{python} , as expected. Fourth step: follow the instructions in Vim's :help syn-include to include python highlighting and apply it to all regions delimited by \begin{python} and \end{python} . My rtex.vim file now looks like this: runtime! syntax/tex.vim unlet! b:current_syntax syntax include @Python syntax/python.vim syntax region pythonCode start="\\begin{python}" end="\\end{python}" contains=@Python The unlet! b:current_syntax command is meant to force the python.vim syntax file to execute even though an existing syntax (TeX) is already active. Problem: If I now ope
Tags (comma-separated)
Save Edits
Cancel