Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/vim/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Regex Vim标记突出显示(列表项和代码块冲突)_Regex_Vim_Syntax_Markdown_Highlight - Fatal编程技术网

Regex Vim标记突出显示(列表项和代码块冲突)

Regex Vim标记突出显示(列表项和代码块冲突),regex,vim,syntax,markdown,highlight,Regex,Vim,Syntax,Markdown,Highlight,我决定进一步了解vim及其语法突出显示。 使用其他示例,我正在创建自己的标记语法文件。我见过,它也有这个问题。 我的问题是在列表项和代码块突出显示之间 代码块: 第一行是空白的 第二行以至少4个空格或1个制表符开头 块以空行结束 例如: Regular text this is code, monospaced and left untouched by markdown another line of code Regular Text Regular text -

我决定进一步了解vim及其语法突出显示。 使用其他示例,我正在创建自己的标记语法文件。我见过,它也有这个问题。 我的问题是在列表项和代码块突出显示之间

代码块:

  • 第一行是空白的
  • 第二行以至少4个空格或1个制表符开头
  • 块以空行结束
例如:

Regular text

    this is code, monospaced and left untouched by markdown
    another line of code

Regular Text
Regular text

- item 1

    - sub item 1
    - sub item 2
- item 2
this is part of item 2
so is this


- item 3, still in the same list
    - sub item 1
    - sub item 2

Regular text, list ends above
代码块的我的Vim语法:

syn match mkdCodeBlock   /\(\s\{4,}\|\t\{1,}\).*\n/ contained nextgroup=mkdCodeBlock  

hi link mkdCodeBlock  comment
无序列表项:

  • 第一行是空白的
  • 第二行以[-+*]开头,后跟空格
  • 列表以空行结束,然后是普通(非列表)行
  • 在行项目之间可以添加任意数量的空行
  • 通过缩进指定子列表(4个空格或1个选项卡)
  • 列表项后的一行普通文本作为该列表项的延续被包括在内
例如:

Regular text

    this is code, monospaced and left untouched by markdown
    another line of code

Regular Text
Regular text

- item 1

    - sub item 1
    - sub item 2
- item 2
this is part of item 2
so is this


- item 3, still in the same list
    - sub item 1
    - sub item 2

Regular text, list ends above
无序列表项定义的我的Vim语法(我只突出显示
[-+*]
):

我无法使高亮显示与列表的最后两个规则和代码块一起工作

这是一个打破我的语法突出显示的示例:

Regular text

- Item 1
- Item 2
part of item 2

    - these 2 line should be highlighted as a list item
    - but they are highlighted as a code block
我目前还不知道如何让突出显示按我所希望的方式工作


忘记添加下面列出的两个规则中使用的“全局”语法规则。这是为了确保它们以空行开头

syn match mkdBlankLine   /^\s*\n/    nextgroup=mkdCodeBlock,mkdListItem transparent

另一个提示:我应该更清楚。在我的语法文件中,列表规则显示在Blockquote规则之前


只需确保mkdListItem的定义在mkdCodeBlock的定义之后,如下所示:

syn match mkdCodeBlock   /\(\s\{4,}\|\t\{1,}\).*\n/ contained nextgroup=mkdCodeBlock  
hi link mkdCodeBlock  comment

syn region  mkdListItem start=/\s*[-*+]\s\+/ matchgroup=pdcListText end=".*" contained nextgroup=mkdListItem,mkdListSkipNL contains=@Spell skipnl 
syn match mkdListSkipNL /\s*\n/ contained nextgroup=mkdListItem,mkdListSkipNL skipnl
hi link mkdListItem  operator

syn match mkdBlankLine   /^\s*\n/    nextgroup=mkdCodeBlock,mkdListItem transparent
Vim文档在
:help:syn define
中说明:

如果多个项目在同一位置匹配,则 定义的最后一个wins。因此,您可以通过 使用与相同文本匹配的项。但关键字总是在 匹配或区域。并且具有匹配大小写的关键字始终位于
忽略大小写的关键字。“

hcs42是正确的。我现在确实记得读过那一节,但我忘记了,直到hcs24提醒我

以下是我更新后的语法(很少有其他调整):

""""""""""""""""""""""""""""""""""""""" " Code Blocks: " Indent with at least 4 space or 1 tab " This rule must appear for mkdListItem, or highlighting gets messed up syn match mkdCodeBlock /\(\s\{4,}\|\t\{1,}\).*\n/ contained nextgroup=mkdCodeBlock """"""""""""""""""""""""""""""""""""""" " Lists: " These first two rules need to be first or the highlighting will be " incorrect " Continue a list on the current line or next line syn match mkdListCont /\s*[^-+*].*/ contained nextgroup=mkdListCont,mkdListItem,mkdListSkipNL contains=@Spell skipnl transparent " Skip empty lines syn match mkdListSkipNL /\s*\n/ contained nextgroup=mkdListItem,mkdListSkipNL " Unorder list syn match mkdListItem /\s*[-*+]\s\+/ contained nextgroup=mkdListSkipNL,mkdListCont skipnl """"""""""""""""""""""""""""""""""""""" “代码块: “使用至少4个空格或1个制表符缩进 必须为mkdListItem显示此规则,否则突出显示会出错 syn match mkdCodeBlock/\(\s\{4,}\\\\t\{1,}\).\n/包含的nextgroup=mkdCodeBlock """"""""""""""""""""""""""""""""""""""" “名单: “前两条规则必须是第一条,否则突出显示将是第一条 “不对 “在当前行或下一行继续列表 syn match mkdListCont/\s*[^-+*].*/contained nextgroup=mkdListCont,mkdListItem,mkdListSkipNL contains=@Spell skipnl transparent “跳过空行 syn match mkdListSkipNL/\s*\n/nextgroup=mkdListItem,mkdListSkipNL “无序列表 syn match mkdListItem/\s*[-*+]\s\+/包含的nextgroup=mkdListSkipNL,mkdListCont skipnl
Tao Zhyn,这可能涵盖了您的用例,但不包括标记语法。在标记中,列表项可能包含一个代码块。您可以看看我的解决方案

问题是vim不允许您这样说:一个块与其容器具有相同的缩进+4个空格。我找到的唯一解决方案是为每种类型的块生成规则,这些块可以包含在每一级缩进的列表项中(实际上我支持42级缩进,但它是一个任意数字)

因此,我有一个markdownCodeBlockInListItemAtLevel1,它必须包含在MarkdownStiteMatlevel1中,它需要至少有8个前导空格,然后一个markdownCodeBlockInListItemAtLevel2,它必须包含在MarkdownStiteMatlevel2中,必须包含在MarkdownStiteMatlevel1中,ant需要ve至少10个前导空格,ecc


我知道几年过去了,但也许有人会认为这个答案很有帮助,因为所有基于缩进的语法都会遇到同样的问题

酷。这使我最终想学习VIM脚本。,我的列表规则在我的blockquote规则之前。你能翻转一下你的例子吗,所以blockquote在列表之前。然后我可以接受你的答案。