当VIM中已经加载语法时,如何突出显示命令?

当VIM中已经加载语法时,如何突出显示命令?,vim,latex,syntax-highlighting,Vim,Latex,Syntax Highlighting,在VIM(v7.2)中加载默认的TeX语法方案后,如何突出显示一个特定TeX命令\foo的所有实例 如果事先没有加载语法方案,我可以轻松完成: :syntax clear :highlight myGroup ctermfg=blue :syntax match myGroup "\\foo\>" 但是我不知道在加载tex语法方案时如何执行。 这不起作用: :syntax clear :set syntax=tex :highlight myGroup ctermfg=blue :syn

在VIM(v7.2)中加载默认的
TeX
语法方案后,如何突出显示一个特定TeX命令
\foo
的所有实例

如果事先没有加载语法方案,我可以轻松完成:

:syntax clear
:highlight myGroup ctermfg=blue
:syntax match myGroup "\\foo\>"
但是我不知道在加载
tex
语法方案时如何执行。 这不起作用:

:syntax clear
:set syntax=tex
:highlight myGroup ctermfg=blue
:syntax match myGroup "\\foo\>"
更新1 实际上,它适用于序言中的命令,但不适用于
文档
环境中的命令

更新2 解决方法是注释掉
/usr/share/vim/vim72/syntax/tex.vim(v47)中处理折叠的一些行:

" Sections, subsections, etc: {{{1
if g:tex_fold_enabled && has("folding")
 syn region texDocZone                  matchgroup=texSection start='\\begin\s*{\s*document\s*}' end='\\end\s*{\s*document\s*}'                                                     fold contains=@texFoldGroup,@texDocGroup,@Spell
 syn region texPartZone                 matchgroup=texSection start='\\part\>'                   end='\ze\s*\\\%(part\>\|end\s*{\s*document\s*}\)'                                  fold contains=@texFoldGroup,@texPartGroup,@Spell
 syn region texChapterZone              matchgroup=texSection start='\\chapter\>'                end='\ze\s*\\\%(chapter\>\|part\>\|end\s*{\s*document\s*}\)'                       fold contains=@texFoldGroup,@texChapterGroup,@Spell
 syn region texSectionZone              matchgroup=texSection start='\\section\>'                end='\ze\s*\\\%(section\>\|chapter\>\|part\>\|end\s*{\s*document\s*}\)'            fold contains=@texFoldGroup,@texSectionGroup,@Spell
 syn region texSubSectionZone           matchgroup=texSection start='\\subsection\>'             end='\ze\s*\\\%(\%(sub\)\=section\>\|chapter\>\|part\>\|end\s*{\s*document\s*}\)'  fold contains=@texFoldGroup,@texSubSectionGroup,@Spell
 syn region texSubSubSectionZone        matchgroup=texSection start='\\subsubsection\>'          end='\ze\s*\\\%(\%(sub\)\{,2}section\>\|chapter\>\|part\>\|end\s*{\s*document\s*}\)'fold contains=@texFoldGroup,@texSubSubSectionGroup,@Spell
 syn region texParaZone                 matchgroup=texSection start='\\paragraph\>'              end='\ze\s*\\\%(paragraph\>\|\%(sub\)*section\>\|chapter\>\|part\>\|end\s*{\s*document\s*}\)'                       fold contains=@texFoldGroup,@texParaGroup,@Spell
 syn region texSubParaZone              matchgroup=texSection start='\\subparagraph\>'           end='\ze\s*\\\%(\%(sub\)\=paragraph\>\|\%(sub\)*section\>\|chapter\>\|part\>\|end\s*{\s*document\s*}\)'     fold contains=@texFoldGroup,@Spell
 syn region texTitle                    matchgroup=texSection start='\\\%(author\|title\)\>\s*{' end='}'                                                                            fold contains=@texFoldGroup,@Spell
 syn region texAbstract                 matchgroup=texSection start='\\begin\s*{\s*abstract\s*}' end='\\end\s*{\s*abstract\s*}'                                                     fold contains=@texFoldGroup,@Spell
"else
" syn region texDocZone                 matchgroup=texSection start='\\begin\s*{\s*document\s*}' end='\\end\s*{\s*document\s*}'                                                     contains=@texFoldGroup,@texDocGroup,@Spell
" syn region texPartZone                        matchgroup=texSection start='\\part\>'                   end='\ze\s*\\\%(part\>\|end\s*{\s*document\s*}\)'                          contains=@texFoldGroup,@texPartGroup,@Spell
" syn region texChapterZone             matchgroup=texSection start='\\chapter\>'                end='\ze\s*\\\%(chapter\>\|part\>\|end\s*{\s*document\s*}\)'                       contains=@texFoldGroup,@texChapterGroup,@Spell
" syn region texSectionZone             matchgroup=texSection start='\\section\>'                end='\ze\s*\\\%(section\>\|chapter\>\|part\>\|end\s*{\s*document\s*}\)'            contains=@texFoldGroup,@texSectionGroup,@Spell
" syn region texSubSectionZone          matchgroup=texSection start='\\subsection\>'             end='\ze\s*\\\%(\%(sub\)\=section\>\|chapter\>\|part\>\|end\s*{\s*document\s*}\)'  contains=@texFoldGroup,@texSubSectionGroup,@Spell
" syn region texSubSubSectionZone       matchgroup=texSection start='\\subsubsection\>'          end='\ze\s*\\\%(\%(sub\)\{,2}section\>\|chapter\>\|part\>\|end\s*{\s*document\s*}\)'contains=@texFoldGroup,@texSubSubSectionGroup,@Spell
" syn region texParaZone                        matchgroup=texSection start='\\paragraph\>'              end='\ze\s*\\\%(paragraph\>\|\%(sub\)*section\>\|chapter\>\|part\>\|end\s*{\s*document\s*}\)'                       contains=@texFoldGroup,@texParaGroup,@Spell
" syn region texSubParaZone             matchgroup=texSection start='\\subparagraph\>'           end='\ze\s*\\\%(\%(sub\)\=paragraph\>\|\%(sub\)*section\>\|chapter\>\|part\>\|end\s*{\s*document\s*}\)'     contains=@texFoldGroup,@Spell
" syn region texTitle                   matchgroup=texSection start='\\\%(author\|title\)\>\s*{' end='}'                                                                            contains=@texFoldGroup,@Spell
" syn region texAbstract                        matchgroup=texSection start='\\begin\s*{\s*abstract\s*}' end='\\end\s*{\s*abstract\s*}'                                             contains=@texFoldGroup,@Spell
endif

问题是存在语法高亮显示,因此未应用
:语法匹配。您需要找出哪个原始语法组突出显示它,并在其中包含它。这对我很有用:

:syntax match myGroup "\\foo\>" containedin=texStatement

问题是存在语法高亮显示,因此未应用
:语法匹配。您需要找出哪个原始语法组突出显示它,并在其中包含它。这对我很有用:

:syntax match myGroup "\\foo\>" containedin=texStatement

它在Vim 7.3中对我有效。你能在没有任何插件的情况下复制它吗(运行
vim-u NONE
)?是的,我能。非常感谢。不幸的是,Vim 7.2是Debian(stable)的最新版本。@PrinceGoulash:如果
\foo
文档
环境中,它对您有用吗?只有在序言中有
\foo
时,它才对我有效。谢谢。它在Vim 7.3中对我有效。你能在没有任何插件的情况下复制它吗(运行
vim-u NONE
)?是的,我能。非常感谢。不幸的是,Vim 7.2是Debian(stable)的最新版本。@PrinceGoulash:如果
\foo
文档
环境中,它对您有用吗?只有在序言中有
\foo
时,它才对我有效。谢谢