syntax - Vim 语法 : match only at the start of region - not subsequent ones

标签 syntax vim

我有以下 Vim 语法文件:

" Vim syntax file
" Language: ScreenplayText - the textual source of ScreenplayXML
" Maintainer: Shlomi Fish <shlomif@iglu.org.il>
" 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.

带有“:”冒号的第二行仍然突出显示。如何防止它突出显示?

感谢您提供任何见解。

问候,

-- 什洛米鱼

附注:这里是 the repository for the vim-screenplay-text highlighting (bitbucket 上的 Mercurial),这是 the screenplay I use to test it (在其 GitHub git 存储库中)。

最佳答案

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!

关于syntax - Vim 语法 : match only at the start of region - not subsequent ones,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14953068/

相关文章:

c# - 覆盖显式接口(interface)实现?

Javascript函数构造

javascript - 在没有 getJSON 的情况下从 Javascript 中的枚举 JSON 子数组中检索数据

python - 为什么元组以字符串格式使用

linux - 我如何去 vim 中的第 X 场比赛?

linux - 如何使用 tmuxinator 在 tmux 中的水平 Pane 内拆分两个垂直 Pane

macos - 在 Mac 10.8 上的 vim 中配置电力线字体

mysql - 为使用 SELECT 语句创建的表添加自增主键

diff - 在 Vim 中保存文件之前我可以看到更改吗?

VIM-如何在插入模式下删除单词?