Expand Group Selection in Vim

I want to create the name of the Italic group, which is the same as Normal , but the text is in italics. My group Normal set to

 Normal ctermfg=251 ctermbg=234 guifg=#cccccc guibg=#242424 

My questions:

  • The correct way to do this is to add term=italic to the following settings

     hi Italic term=italic ctermfg=251 ctermbg=234 guifg=#cccccc guibg=#242424 
  • I want to do this in a general way, i.e. I want to define Italic so that the setting works for all colorscheme (the above will work only for my specific color scheme). Is there any way to do this? sort of

     hi Italic extends Normal term=italic 
+3
source share
1 answer

To solve this problem, you can create a highlight group using a script. The function below takes three string arguments: the name of the group for the base selection, the name of the group to be created, and a string containing additional selection of properties (or properties for overwriting).

 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 

So the challenge

 :call ExtendHighlight('Normal', 'Italic', 'term=italic') 

creates a new group called Italic that highlights Normal highlighting the term=italic attribute string.

Note that custom highlight groups remain unchanged in the color scheme switching. To fix this behavior, you can update the group when the current color scheme changes.

 :autocmd ColorScheme * call ExtendHighlight('Normal', 'Italic', 'term=italic') 
+4
source

All Articles