简体   繁体   中英

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

I'm using Vim 7.3 on Ubuntu linux.

When I'm editing a YAML file

This:
    fnordy fnord: fnord
    fnords: super fnord

"fnords" would be colorized, but "fnordy fnords" would not be.

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.

UPDATE

:color 
slate

:echo &ft
yaml

On fnord: fnordy (at the beginning of the line): yamlBlockMappingKey

On fnordy fnord: fnord (at the beginning of the line): yamlPlainScalar

As a result of steffen's help, I compared both of the parsing commands.

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

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. Have a look at 3.2.1.1 in the specification and at this example .

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:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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