Skip to content

Instantly share code, notes, and snippets.

@kawarimidoll
Last active December 9, 2021 00:59
Show Gist options
  • Save kawarimidoll/302b03fc6e9300786f54cfafb9150fe3 to your computer and use it in GitHub Desktop.
Save kawarimidoll/302b03fc6e9300786f54cfafb9150fe3 to your computer and use it in GitHub Desktop.
Merge highlight in Vim or Neovim

MergeHighlight.vim

Merge existing highlight settings in Vim or Neovim.

Installation

Put codes in your configuration file, such as .vimrc or init.vim.

Usage

highlight Red guifg=#ff0000
highlight Bold gui=bold
MergeHighlight RedBold Red Bold
" same as ↓
" highlight RedBold guifg=#ff0000 gui=bold
command! -nargs=+ -complete=highlight MergeHighlight call s:MergeHighlight(<q-args>)
function! s:MergeHighlight(args) abort "{{{
let l:args = split(a:args)
if len(l:args) < 2
echoerr '[MergeHighlight] At least 2 arguments are required.'
echoerr 'New highlight name and source highlight names.'
return
endif
" skip 'links' and 'cleared'
execute 'highlight' l:args[0] l:args[1:]
\ ->map({_, val -> substitute(execute('highlight ' . val), '^\S\+\s\+xxx\s', '', '')})
\ ->filter({_, val -> val !~? '^links to' && val !=? 'cleared'})
\ ->join()
" for the envirionments that doesn't support arrow method
" execute 'highlight' l:args[0] join(
" \ filter(
" \ map(
" \ l:args[1:],
" \ {_, val -> substitute(execute('highlight ' . val), '^\S\+\s\+xxx\s', '', '')}
" \ ),
" \ {_, val -> val !~? '^links to' && val !=? 'cleared'}
" \ ))
endfunction "}}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment