在Vim中扩展突出显示组
我想创建一个名为Italic
的组,使其完全像
Normal
,但带有斜体文本.我的Normal
组是
设置为
I want to create a group named Italic
to be exactly like
Normal
but with text in italic. My Normal
group is
set to
Normal ctermfg=251 ctermbg=234 guifg=#cccccc guibg=#242424
我的问题是:
-
正确的方法是添加
term=italic
设置如下?
hi Italic term=italic ctermfg=251 ctermbg=234 guifg=#cccccc guibg=#242424
我想以一种通用的方式来做,即定义Italic
这样
该设置适用于所有颜色方案(以上仅适用于
用于我当前的colorcheme).有办法做到吗?像
I want to do it in a generic fashion, i.e., define Italic
such
that the setting works for all colorschemes (the above will work only
for my current colorscheme). Is there a way accomplish it? Something like
hi Italic extends Normal term=italic
要解决此问题,您可以按脚本创建突出显示组.这 下面的函数采用三个字符串参数:要作为基础的组的名称 突出显示,要创建的组的名称以及包含其他内容的字符串 突出显示属性(或要覆盖的属性).
To solve this issue you can create the highlighting group by script. The function below takes three string arguments: name of the group to base highlighting on, name of the group to create, and string containing additional highlighting properties (or properties to overwrite).
function! ExtendHighlight(base, group, add)
redir => basehi
sil! exe 'highlight' a:base
redir END
let grphi = split(basehi, '\n')[0]
let grphi = substitute(grphi, '^'.a:base.'\s\+xxx', '', '')
sil exe 'highlight' a:group grphi a:add
endfunction
因此,通话
:call ExtendHighlight('Normal', 'Italic', 'term=italic')
创建一个名为Italic
的新组,该组扩展了Normal
突出显示的位置
term=italic
属性字符串.
creates a new group called Italic
that extends Normal
highlighting by the
term=italic
attribute string.
请注意,自定义突出显示组在颜色方案上保持不变 交换.若要更正此行为,您可以在当前 颜色方案的变化.
Note that custom highlighting groups remain unchanged on color-scheme switching. To correct this behavior you can update the group when the current color-scheme changes.
:autocmd ColorScheme * call ExtendHighlight('Normal', 'Italic', 'term=italic')