Last active
August 2, 2023 08:18
-
-
Save AndrewRadev/ed7cdc5fcd0e19c8164d7e3ee3e583a8 to your computer and use it in GitHub Desktop.
Try to take the current colorscheme's highlights and put them in a file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" Adapted from https://vi.stackexchange.com/a/16111 | |
" | |
command! -nargs=1 DumpHighlight call s:DumpHighlight(<q-args>) | |
function! s:DumpHighlight(filename) abort | |
let output = execute('hi', 'silent!') | |
let colors_name = fnamemodify(a:filename, ':r') | |
let highlights =<< trim eval EOF | |
hi clear | |
if exists("syntax_on") | |
syntax reset | |
endif | |
let g:colors_name = "{colors_name}" | |
EOF | |
for line in split(output, "\n") | |
let link = matchstr(line, 'links to \zs\w\+') | |
let group = matchstr(line, '^\k\+') | |
let hl = '' | |
if empty(link) | |
let attrs = matchstr(line, '\<xxx \zs[^\n]*') | |
if attrs !=# 'cleared' | |
call add(highlights, printf('hi %s %s', group, attrs)) | |
endif | |
elseif group[0] =~# '[a-z]' | |
" It's a language-specific highlight like vimString or rubyClassName, | |
" let's ignore it | |
else | |
call add(highlights, printf('hi! link %s %s', group, link)) | |
endif | |
endfor | |
call writefile(highlights, a:filename) | |
exe 'split ' .. a:filename | |
endfunction |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment