如何在VIM中加载语法时突出显示命令?

时间:2013-01-04 12:42:23

标签: vim latex syntax-highlighting

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

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

: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

实际上,它适用于前导码中的命令,但不适用于document环境中的命令。

更新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

1 个答案:

答案 0 :(得分:1)

问题在于存在语法突出显示,因此未应用:syntax match。您需要找出哪个原始语法组突出显示它并在其中contain。这对我有用:

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