2011-09-10 29 views
1

在膠乳,部分看起來像:LaTeX的部分vim的突出

\section{Section Title} 

我想強調這樣的部分,或部分的標題。我試圖把~/.vim/bundle/latexrc/after/syntax/tex.vim如下:(注意,這種語法不是由默認tex.vim語法文件來處理它僅僅定義「部分地區」,這對我來說是非常不值錢。)

syn match texSectioning "\\section\>" skipwhite nextgroup=texSectioningTitle 
syn region texSectioningTitle  contained matchgroup=Delimiter start='{' end='}' [email protected] 
syn cluster texSectioningGroup  contains=texMatcher,texComment,texDelimiter 

然後我定義我的配色方案如下:

hi texSectioning gui=bold guifg=red 

並沒有任何反應;也就是說,在我的LaTeX代碼中,部分標題不會顯示爲紅色(即使我完全重新加載文件後)。

對於vim的語法如何工作以及如何調試,我感到十分困惑。

編輯 一些更多信息:它有時有效,有時不會。 完全不可預知。可能是什麼問題呢?病原?還有別的嗎?我完全困惑。

+0

你能描述一下你想達到什麼樣的亮點,以及它如何區別於默認的TeX突出顯示? –

+0

它在帖子中:*我想突出顯示這些部分或部分標題。*。這不包含在標準的'tex.vim'語法文件中。 –

回答

0

下面是答案:tex.vim將區域中的文本分開,其中句法必須爲明確允許。關鍵的因素是,命令:

syn cluster texChapterGroup [email protected] 

這是說給一個texChapterGroup內,語法集羣texSectioningGroup允許VIM。接下來要做的就是像往常一樣定義該羣集。

另一個細節是該區域texSectioningTitle必須contained,否則將在乳膠匹配任意對{}

因此,一個完整的解決方案是這樣的:

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

編輯這是爲什麼的行爲顯然是不可預測的:Vim不會讀取整個文件,以找出語法。因此,在一個足夠大的章節中,我的章節語法會起作用,因爲vim沒有足夠遠以查看它在章節區域中。

0

您已經定義了新的語法項目texSectioningtexSectioningTitletexSectioningGroup,但是你有沒有他們連接到高亮組,所以Vim不知道如何顯示它們。嘗試添加這些行:

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

StatementStringComment色素是由您正在使用的colourscheme定義。這些僅僅是示例:您可以將它們替換爲colourscheme文件中定義的任何組。

0

只是爲了更新信息以突出顯示部分。使用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