简体   繁体   English

当包含空格时,如何让Vim突出显示YAML映射键?

[英]How do I get Vim to highlight YAML mapping key when it contains a space?

I'm using Vim 7.3 on Ubuntu linux. 我在Ubuntu linux上使用Vim 7.3。

When I'm editing a YAML file 当我正在编辑YAML文件时

This:
    fnordy fnord: fnord
    fnords: super fnord

"fnords" would be colorized, but "fnordy fnords" would not be. “fnords”会被着色,但“fnordy fnords”不会。

fnords然后fnordy fnord

fnordy fnord然后fnord

How can I fix this? 我怎样才能解决这个问题? I'm looking at my /usr/share/vim/vim73/syntax/yaml.vim file, but I don't understand it enough to fix this. 我正在查看我的/usr/share/vim/vim73/syntax/yaml.vim文件,但我不太了解它。

UPDATE UPDATE

:color 
slate

:echo &ft
yaml

On fnord: fnordy (at the beginning of the line): yamlBlockMappingKey fnord: fnordy (在行的开头):yamlBlockMappingKey

On fnordy fnord: fnord (at the beginning of the line): yamlPlainScalar fnordy fnord: fnord (在行的开头):yamlPlainScalar

As a result of steffen's help, I compared both of the parsing commands. 由于steffen的帮助,我比较了两个解析命令。

The current script looks like this: 当前脚本如下所示:

execute 'syn match yamlBlockMappingKey /^\s*\zs'.s:ns_plain_out.'\ze\s*:\%(\s\|$\)/ '.
            \'nextgroup=yamlKeyValueDelimiter'

The problem, specifically, is the s:ns_plain_out , which is a non-space pattern 具体来说,问题是s:ns_plain_out ,这是一种非空间模式

So I changed the pattern to simply match on any character: 所以我将模式更改为简单匹配任何字符:

execute 'syn match yamlBlockMappingKey /^\s*\zs.*\ze\s*:\%(\s\|$\)/ '.

Which fixes this particular issue. 哪个修复了这个特殊问题。

According to the YAML specification , spaces are valid characters in keys of mappings. 根据YAML规范 ,空格是映射键中的有效字符。 Have a look at 3.2.1.1 in the specification and at this example . 请看规范和本例中的3.2.1.1。

I'd say that the highlighting is correct. 我会说突出显示是正确的。 You have an unmeant linebreak in your first value using quotes (like in this example ). 您使用引号在第一个值中有一个不显眼的换行符(如本例所示 )。

Building on the accepted answer, here's what I put in my .vimrc to get this fix without editing any core vim files: 基于已接受的答案,这是我在.vimrc中放置的内容,无需编辑任何核心vim文件即可获得此修复:

autocmd FileType yaml execute
      \'syn match yamlBlockMappingKey /^\s*\zs.*\ze\s*:\%(\s\|$\)/'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM