1

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
4

1 に答える 1

1

問題は、既存の構文強調表示があるため、:syntax match適用されないことです。どの元の構文グループがそれを強調表示しているかを調べる必要がcontainあります。これは私のために働く:

:syntax match myGroup "\\foo\>" containedin=texStatement
于 2013-01-05T12:18:05.160 に答える