在Vim中扩展突出显示组 [英] Extending a highlighting group in Vim

查看:92
本文介绍了在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

我的问题是:

  1. 正确的方法是添加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')
    

    这篇关于在Vim中扩展突出显示组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆