我目前有一个解析日志文件的语法文件,与以下内容非常相似[这是针对 syslog 的]:
syn match syslogText /.*$/
syn match syslogFacility /.\{-1,}:/ nextgroup=syslogText skipwhite
syn match syslogHost /\S\+/ nextgroup=syslogFacility,syslogText skipwhite
syn match syslogDate /^.\{-}\d\d:\d\d:\d\d/ nextgroup=syslogHost skipwhite
我想使用地图来切换给定组(比如说 syslogHost)是否被隐藏。有没有办法做类似以下伪代码的事情:
map <leader>ch :syn match syslogHost conceal!
从而在 syslogHost 之间切换定义:
syn match syslogHost /\S\+/ nextgroup=syslogFacility,syslogText skipwhite
and
syn match syslogHost /\S\+/ nextgroup=syslogFacility,syslogText skipwhite conceal
Thanks.
I think做到这一点的唯一方法是使用一个函数:
map <leader>ch :call ToggleGroupConceal('sysLogHost')<CR>
function! ToggleGroupConceal(group)
" Get the existing syntax definition
redir => syntax_def
exe 'silent syn list' a:group
redir END
" Split into multiple lines
let lines = split(syntax_def, "\n")
" Clear the existing syntax definitions
exe 'syn clear' a:group
for line in lines
" Only parse the lines that mention the desired group
" (so don't try to parse the "--- Syntax items ---" line)
if line =~ a:group
" Get the required bits (the syntax type and the full definition)
let matcher = a:group . '\s\+xxx\s\+\(\k\+\)\s\+\(.*\)'
let type = substitute(line, matcher, '\1', '')
let definition = substitute(line, matcher, '\2', '')
" Either add or remove 'conceal' from the definition
if definition =~ 'conceal'
let definition = substitute(definition, ' conceal\>', '', '')
exe 'syn' type a:group definition
else
exe 'syn' type a:group definition 'conceal'
endif
endif
endfor
endfunction
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)