I am using vim to write latex. I would like to highlight the latex comments using a different file type. (For example I would like to highlight the latex comments using c++ formatting).
Is there a way to do this?
(Edit)
Example:
\section{Introduction}
% This is a comment. I would like to higlight comments using the
% syntax highlighting from c++ files (so that keywords are higlighted)
bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla ...
(Note: the end goal is not to use c++ higlighting but this makes the example more straight forward)
This is actually pretty easy to do, just create ~/.vim/after/syntax/plaintex.vim with the content:
let s:saved_syntax = b:current_syntax
unlet b:current_syntax
syntax include @Cpp syntax/cpp.vim
syntax match cppInComment /.*/ contained containedin=initexComment contains=@Cpp transparent
let b:current_syntax = s:saved_syntax
and ~/.vim/after/syntax/tex.vim with:
let s:saved_syntax = b:current_syntax
unlet b:current_syntax
syntax include @Cpp syntax/cpp.vim
syntax match cppInComment /.*/ contained containedin=texComment contains=@Cpp transparent
let b:current_syntax = s:saved_syntax
This includes c++ syntax as a sub-syntax of the TeX syntax and just says that C++ code should be highlighted within comments.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With