2013-02-19 58 views
3

我有以下Vim的語法文件:Vim的語法:比賽僅在該區域的開始 - 而不是後續各個

" Vim syntax file 
" Language: ScreenplayText - the textual source of ScreenplayXML 
" Maintainer: Shlomi Fish <[email protected]> 
" Home: http://search.cpan.org/dist/XML-Grammar-Screenplay/ 
" 
" Author: Shlomi Fish 
" Filenames: *.screenplay-text.txt 
" Last Change: Thu Jul 3 00:59:42 IDT 2008 
" Version: 0.0.1 

" Thanks to Andy Wokula for his help on: 
" https://groups.google.com/group/vim_use/browse_thread/thread/6c0906617d67864e/a21938c5df1d15cb?show_docid=a21938c5df1d15cb 

" Quit if syntax file is already loaded 
if version < 600 
    syntax clear 
elseif exists("b:current_syntax") 
    finish 
endif 

syntax sync minlines=50 

" syntax match screenplayTextComment /<!--\_.\{-0,}-->/ 
" syntax match screenplayTextDescription /^ *\[\_.\{-0,}\]/ 
syntax region screenplayTextComment start="<!--" end="-->" 
syntax region screenplayTextDescription start="^ *\[" end="]" 

" syntax region screenplayTextSaying start=/\(^\s*\n\)\@<=\_^\(+\{2,\}\|[^[:+]*\):/ end=/^\s*$/ contains=screenplayTextAddress,screenplayTextInnerDesc 
syntax region screenplayTextSaying start=/\(^\s*\n\)\@<=\_^\(+\{2,\}\|[^[:+]*\):/ end=/^\s*$/ contains=screenplayTextAddress 

" syntax match screenplayTextAddress /\%^\(+\{2,\}\|[^[:+]*\):/ contained nextgroup=screenplayTextInnerDesc 
syntax match screenplayTextAddress /[^:]\+:/ contained nextgroup=screenplayTextSayingAfterAddress 

syntax region screenplayTextSayingAfterAddress contained 
" syntax match screenplayTextInnerDesc /\[\_.\{-0,}\]/ contained nextgroup=screenplayTextInnerDesc 


" For debugging - remove. 
" hi def link screenplayTextSaying Statement 

hi def link screenplayTextComment Comment 
hi def link screenplayTextDescription PreProc 
hi def link screenplayTextInnerDesc PreProc 
hi def screenplayTextAddress  term=bold cterm=bold gui=bold 

其目的是爲XML-Grammar-Screenplay,但screenplayTextAddress仍然突出的東西,在後續行以「: 「,如:

Kate: Of course! See, my obsession with the Bible continued throughout my 
life, and later on I became a scholar: first as a married woman who just 
hanged around universities and learned things from the male professors 
and students, later on as someone who helped some professors with their 
research and eventually got credited, and as time progressed, 
I got a B.A., and then a Ph.D., and am now a professor. 

帶」:「冒號的第二行仍然被突出顯示。我如何防止突出顯示?

感謝您的任何見解。

問候,

- 施洛米魚

P.S:這裏是the repository for the vim-screenplay-text highlighting(上一到位桶水銀之一),這裏是the screenplay I use to test it(在GitHub上的Git倉庫)。

回答

2

screenplayTextSaying組包含兩個分支;我會將它們分成兩個單獨的區域,然後使用matchgroup直接在以冒號結尾的地址區域開始處突出顯示。見:help :syn-matchgroup

syntax region screenplayTextSaying start=/\(^\s*\n\)\@<=\_^+\{2,\}:/ end=/^\s*$/ 
syntax region screenplayTextSaying end=/^\s*$/ matchgroup=screenplayTextAddress start=/\(^\s*\n\)\@<=\_^[^[:+]*:/ 
"syntax match screenplayTextAddress /[^:]\+:/ Not needed any more! 
+0

謝謝!我用Freenode的#vim上的一些人的幫助來實現我所需要的變體。我應該注意matchgroup = ...必須在開始和結束之前出現。下次,請測試您的代碼。 – 2013-02-20 13:25:35

+1

我明確地將'matchgroup ='_after_' end ='放在''start ='後面,我測試了這個。下一次,請仔細閱讀文檔;-) – 2013-02-20 13:35:02

0

它似乎是唯一識別段落第一行的方法,它是一個空行。

" Define blank line at first 
syntax match EmptyLines "\(^\s*\n\)\+" nextgroup=FistLine, Description 

" Then define Fist line 
syntax region FirstLine start=+^[^\<\[]+ oneline contains=Address 

" Then define Address 
syntax match Address "^[^<\[]+:" contained 

" Description 
syntax match Description "\[[^\[]+\]" 

" Comment 
" Comment match code 

" For the rest of text, just give them a general format 

我沒有測試代碼,只是提供了一個想法。請自行嘗試。希望這可以幫助。

+0

嗨,我不是在談論一個分號 - «;»,而是一個冒號 - «:»,此外,話語的薩耶爾可能與匹配\ w的範圍拋開包含其他字符作爲空間或其他。此外,我不關心不突出冒號本身,我只想在第一行中突出顯示^ [:] \ +:而不是後面的包含冒號的行。 – 2013-02-19 10:50:14

+0

@ShlomiFish,我誤解了你的問題。現在更新。 – 2013-02-19 12:18:16