From 9fbe25fee7d1e89fa6683912699a0bdd363d519e Mon Sep 17 00:00:00 2001 From: "Kenneth Benzie (Benie)" Date: Sat, 24 Dec 2016 13:19:32 +0000 Subject: [PATCH] Add function to clone highlight groups with attrs --- plugin/functions.vim | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/plugin/functions.vim b/plugin/functions.vim index f668e21..52d568c 100644 --- a/plugin/functions.vim +++ b/plugin/functions.vim @@ -5,6 +5,29 @@ function! FoldText() return line.' '.string(v:foldend - v:foldstart + 1).' lines ' endfunction +" Derived from http://stackoverflow.com/a/1333025 +function! CloneHighlightGroupWithAttributes(group, new_group, attributes) + " Get group details, resolving group links. + redir => group + exe "silent hi " . a:group + redir END + while group =~ "links to" + let index = stridx(group, "links to") + len("links to") + let linked_group = strpart(group, index + 1) + redir => group + exe "silent hi " . linked_group + redir END + endwhile + + " Get highlight parameters and existing remove attributes. + let parameters = matchlist(group, '\\s\+\(.*\)')[1] + let parameters = substitute(parameters, '\(c\?term\|gui\)=\w\+', '', 'g') + + " Create the cloned highlight group with new attributes. + exe 'hi '.a:new_group.' '.parameters. + \' term='.a:attributes.' cterm='.a:attributes.' gui='.a:attributes +endfunction + " Strip trailing whitespace function! StripWhitespace() let l = line(".")