vim中的LaTeX部分突出显示

vim中的LaTeX部分突出显示,vim,latex,syntax-highlighting,tex,Vim,Latex,Syntax Highlighting,Tex,在LaTeX中,一个截面看起来像: \section{Section Title} 我想强调这些章节或章节标题。我试图将以下内容放入~/.vim/bundle/latexrc/after/syntax/tex.vim: syn match texSectioning "\\section\>" skipwhite nextgroup=texSectioningTitle syn region texSectioningTitle contained matchgroup=De

在LaTeX中,一个截面看起来像:

\section{Section Title}
我想强调这些章节或章节标题。我试图将以下内容放入
~/.vim/bundle/latexrc/after/syntax/tex.vim

syn match texSectioning "\\section\>" skipwhite nextgroup=texSectioningTitle
syn region texSectioningTitle       contained matchgroup=Delimiter start='{'    end='}' contains=@texSectioningGroup
syn cluster texSectioningGroup      contains=texMatcher,texComment,texDelimiter
(请注意,这种语法不是由默认的
tex.vim
语法文件处理的。它只定义了“分区”,这对我来说毫无价值。)

然后,我在配色方案中定义以下内容:

hi texSectioning gui=bold guifg=red
什么也没发生;也就是说,在我的LaTeX代码中,节标题不会显示为红色(即使在我完全重新加载文件之后)

我完全搞不懂vim的语法是如何工作的,以及如何调试它

编辑
更多信息:它有时有效,有时无效。完全不可预测。有什么问题吗?病原体还有别的吗?我完全不明白。

您已经定义了新的语法项
texSectioning
texSectioningTitle
texSectioningGroup
,但是您没有将它们链接到突出显示组,所以Vim不知道如何显示它们。尝试添加以下行:

hi def link texSectioning Statement
hi def link texSectioningTitle String
hi def link texSectioningGroup Comment

语句
字符串
注释
颜色由您使用的配色方案定义。这些只是示例:您可以将它们替换为ColorScheme文件中定义的任何组。

答案如下:tex.vim将文本划分为区域,其中必须明确允许语法。关键要素是命令:

syn cluster texChapterGroup contains=@texSectioningGroup
这对vim说,在
texChapterGroup
中,允许使用语法集群
texSectioningGroup
。接下来要做的就是像往常一样定义集群

另一个细节是区域
texSectioningTitle
必须包含
,否则它将匹配LaTeX中的任意
{}

因此,完整的解决方案如下所示:

syn match texSectioningCommand '\\section\>' skipwhite     nextgroup=texSectioningTitle contains=@texSectioningGroup
syn region texSectioningTitle        start='{'  end='}' contained
syn cluster texSectioningGroup contains=texSectioningCommand
syn cluster texChapterGroup contains=@texSectioningGroup

Edit以下是行为明显不可预测的原因:vim不会读取整个文件来找出语法。因此,在一个足够大的章节中,我的章节语法会起作用,因为vim没有走得足够远,无法看到它在章节区域中。

只是为了更新信息,以便轻松突出显示章节。使用containedin意味着所有其他语法匹配都包含此新语法匹配。然后定义你想要的颜色

syn match texSectioningCommand '\\section\>' containedin=ALLBUT,texComment
hi texSectioningCommand guifg=#ec5f67 ctermfg=203
或者,可以将一个简单的新语法匹配添加到texFoldGroup中,以便在块文档中进行计算

syn match texSectioningCommand '\\section\>'
syn cluster texFoldGroup add=texSectioningCommand
hi texSectioningCommand guifg=#ec5f67 ctermfg=203

你能描述一下你想实现什么样的突出显示,以及它与默认的TeX突出显示有什么不同吗?在帖子中:我想突出显示这样的章节,或者章节标题。。标准的
tex.vim
语法文件不包括这一点。