自定义Vim中的语法突出显示

前端之家收集整理的这篇文章主要介绍了自定义Vim中的语法突出显示前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
如何保留文件类型的所有当前格式,但添加功能.

我想突出显示.vim文件中的颜色,以便突出显示终端将如何解析它的每种颜色.

我创建了一个包含以下内容的vim.vim文件

syn keyword yellow yellow containedin=All                                                    
highlight yellow ctermfg=yellow                                                              

syn keyword red red containedin=all                                                          
highlight red ctermfg=red

并将其放入〜/ .vim / after / Syntax / vim.vim中

正如建议here.

这没有效果.

更新

事实上,当我说我的改变没有效果时,我错了.如果您在一行上单独键入黄色,它将突出显示为黄色.不幸的是,这并没有解决我的问题.

添加Al描述的F3功能.

当我f3超过黄色(在上下文中ctermfg =黄色)时它返回:

hi<vimHiCtermColor> trans<vimHiCtermColor> lo<vimHiCtermColor> FG:-1 BG:-1

然后:syn list vimHiCtermColor返回:

--- Syntax items ---
vimHiCtermColor xxx contained lightmagenta darkgray lightgrey darkgrey lightgreen lightgray darkmagenta gray white red grey darkred brown darkblue darkgreen lightblue yellow cyan
                   contained lightcyan lightred black blue green magenta darkcyan darkyellow

我检查了:syn list darkgray(我还没有定义)看它是否存在:

--- Syntax items ---
E28: No such highlight group name: darkgray
Hit ENTER or type command to continue

我应该从哪里出发?

这里只是黄色这个词的直接答案.

syn cluster vimHiCtermColors contains=vimHiCtermColorYellow
syn keyword vimHiCtermColorYellow yellow contained

syn match  vimHiCtermFgBg   contained   "\ccterm[fb]g="he=e-1   nextgroup=vimNumber,vimHiCtermColor,@vimHiCtermColors,vimFgBgAttrib,vimHiCtermError

highlight vimHiCtermColorYellow ctermfg=yellow

这是一个为所有彩色终端名称着色的解决方案.它们仅在终端(而不是GUI)中着色,并且其他属性(256色终端,GUI颜色,诸如粗体的属性)根本不突出显示.为了进一步扩展这一点,您可能需要某种脚本来迭代所有可能的值.

syn cluster vimHiCtermColors contains=vimHiCtermColorBlack,vimHiCtermColorBlue,vimHiCtermColorBrown,vimHiCtermColorCyan,vimHiCtermColorDarkBlue,vimHiCtermColorDarkcyan,vimHiCtermColorDarkgray,vimHiCtermColorDarkgreen,vimHiCtermColorDarkgrey,vimHiCtermColorDarkmagenta,vimHiCtermColorDarkred,vimHiCtermColorDarkyellow,vimHiCtermColorGray,vimHiCtermColorGreen,vimHiCtermColorGrey,vimHiCtermColorLightblue,vimHiCtermColorLightcyan,vimHiCtermColorLightgray,vimHiCtermColorLightgreen,vimHiCtermColorLightgrey,vimHiCtermColorLightmagenta,vimHiCtermColorLightred,vimHiCtermColorMagenta,vimHiCtermColorRed,vimHiCtermColorWhite,vimHiCtermColorYellow

syn keyword vimHiCtermColorBlack black contained
syn keyword vimHiCtermColorBlue blue contained
syn keyword vimHiCtermColorBrown brown contained
syn keyword vimHiCtermColorCyan cyan contained
syn keyword vimHiCtermColorDarkBlue darkBlue contained
syn keyword vimHiCtermColorDarkcyan darkcyan contained
syn keyword vimHiCtermColorDarkgray darkgray contained
syn keyword vimHiCtermColorDarkgreen darkgreen contained
syn keyword vimHiCtermColorDarkgrey darkgrey contained
syn keyword vimHiCtermColorDarkmagenta darkmagenta contained
syn keyword vimHiCtermColorDarkred darkred contained
syn keyword vimHiCtermColorDarkyellow darkyellow contained
syn keyword vimHiCtermColorGray gray contained
syn keyword vimHiCtermColorGreen green contained
syn keyword vimHiCtermColorGrey grey contained
syn keyword vimHiCtermColorLightblue lightblue contained
syn keyword vimHiCtermColorLightcyan lightcyan contained
syn keyword vimHiCtermColorLightgray lightgray contained
syn keyword vimHiCtermColorLightgreen lightgreen contained
syn keyword vimHiCtermColorLightgrey lightgrey contained
syn keyword vimHiCtermColorLightmagenta lightmagenta contained
syn keyword vimHiCtermColorLightred lightred contained
syn keyword vimHiCtermColorMagenta magenta contained
syn keyword vimHiCtermColorRed red contained
syn keyword vimHiCtermColorWhite white contained
syn keyword vimHiCtermColorYellow yellow contained

syn match  vimHiCtermFgBg   contained   "\ccterm[fb]g="he=e-1   nextgroup=vimNumber,vimHiCtermError

highlight vimHiCtermColorBlack ctermfg=black
highlight vimHiCtermColorBlue ctermfg=blue
highlight vimHiCtermColorBrown ctermfg=brown
highlight vimHiCtermColorCyan ctermfg=cyan
highlight vimHiCtermColorDarkBlue ctermfg=darkBlue
highlight vimHiCtermColorDarkcyan ctermfg=darkcyan
highlight vimHiCtermColorDarkgray ctermfg=darkgray
highlight vimHiCtermColorDarkgreen ctermfg=darkgreen
highlight vimHiCtermColorDarkgrey ctermfg=darkgrey
highlight vimHiCtermColorDarkmagenta ctermfg=darkmagenta
highlight vimHiCtermColorDarkred ctermfg=darkred
highlight vimHiCtermColorDarkyellow ctermfg=darkyellow
highlight vimHiCtermColorGray ctermfg=gray
highlight vimHiCtermColorGreen ctermfg=green
highlight vimHiCtermColorGrey ctermfg=grey
highlight vimHiCtermColorLightblue ctermfg=lightblue
highlight vimHiCtermColorLightcyan ctermfg=lightcyan
highlight vimHiCtermColorLightgray ctermfg=lightgray
highlight vimHiCtermColorLightgreen ctermfg=lightgreen
highlight vimHiCtermColorLightgrey ctermfg=lightgrey
highlight vimHiCtermColorLightmagenta ctermfg=lightmagenta
highlight vimHiCtermColorLightred ctermfg=lightred
highlight vimHiCtermColorMagenta ctermfg=magenta
highlight vimHiCtermColorRed ctermfg=red
highlight vimHiCtermColorWhite ctermfg=white
highlight vimHiCtermColorYellow ctermfg=yellow

说明

如果你查看colors / vim.vim并搜索cterm,你会看到一行

syn match  vimHiCtermFgBg   contained   "\ccterm[fb]g="he=e-1   nextgroup=vimNumber,vimHiCtermError

这表示当遇到ctermfg =或ctermbg =时,将下一个单词突出显示为vimNumber,vimFgBgAttrib或vimHiCtermError.我们看到vimHiCtermColor(上面几行)

syn keyword vimHiCtermColor contained   black blue brown cyan darkBlue darkcyan darkgray darkgreen darkgrey darkmagenta darkred darkyellow gray green grey lightblue lightcyan lightgray lightgreen lightgrey lightmagenta lightred magenta red white yellow

这将列出所有颜色终端名称,并将它们突出显示为具有相同语法组的关键字.因此,我们可以单独突出显示它们,而不是一起突出显示它们.上面第一个解决方案的四行描述了以下步骤:

>在步骤2中创建一个包含每个组的新集群@vimHiCtermColors.
>为每个颜色值添加一个新关键字.
>修改vimHiCtermFgBg定义以使用@vimHiCtermColors而不是vimHiCtermColor.
>根据需要突出显示每个关键字.

你尝试过的东西不起作用的原因是双重的.首先,下一组中指定的语法组优先于一般组(特别是黄色组).但是,你可能会说,“怎么样包含= ALL?”这是第二点.关键字是单个单元,不能包含任何其他内容.原始的vimHiCtermColor组是所有关键字,因此您的containsin = ALL无法覆盖它.如果vimHiCtermColor是匹配而不是关键字,它可能有效.

原文链接:https://www.f2er.com/bash/387128.html

猜你在找的Bash相关文章