Vim: Highlight a latex comment using a different file type.

I use vim to write latex. I would like to highlight latex comments using a different file type. (For example, I would like to highlight latex comments using C ++ formatting).

Is there any 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 ultimate goal is not to use C ++ higlighting, but this makes the example more direct)

+3
source share
4 answers

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

++ TeX , ++ .

+3

:h contained. , - syn, ++, .

:syntax keyword Test    int   contained
:syntax match   Comment "^%"  contains=Test

?

0

, , . Haskell "" , LaTeX Haskell . . vim plugin, LaTeX Haskell .

0

, Latex . , .

If you are not comfortable with the syntax definition, you can use Google for the syntax file and install it. However, I usually do not replace the syntax file from the Internet. I am uploading a new syntax file only for my VIM account.

I have blogs on VIM. Not sure this will help.

-1
source

Source: https://habr.com/ru/post/1752468/


All Articles