├── .gitignore ├── LICENSE ├── README.md ├── autoload └── colorexp │ ├── colors.vim │ ├── export.vim │ ├── names.vim │ ├── palette.vim │ └── palette9.vim └── plugin └── colorexp.vim /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | build/ 12 | develop-eggs/ 13 | dist/ 14 | downloads/ 15 | eggs/ 16 | .eggs/ 17 | lib/ 18 | lib64/ 19 | parts/ 20 | sdist/ 21 | var/ 22 | wheels/ 23 | share/python-wheels/ 24 | *.egg-info/ 25 | .installed.cfg 26 | *.egg 27 | MANIFEST 28 | 29 | # PyInstaller 30 | # Usually these files are written by a python script from a template 31 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 32 | *.manifest 33 | *.spec 34 | 35 | # Installer logs 36 | pip-log.txt 37 | pip-delete-this-directory.txt 38 | 39 | # Unit test / coverage reports 40 | htmlcov/ 41 | .tox/ 42 | .nox/ 43 | .coverage 44 | .coverage.* 45 | .cache 46 | nosetests.xml 47 | coverage.xml 48 | *.cover 49 | *.py,cover 50 | .hypothesis/ 51 | .pytest_cache/ 52 | cover/ 53 | 54 | # Translations 55 | *.mo 56 | *.pot 57 | 58 | # Django stuff: 59 | *.log 60 | local_settings.py 61 | db.sqlite3 62 | db.sqlite3-journal 63 | 64 | # Flask stuff: 65 | instance/ 66 | .webassets-cache 67 | 68 | # Scrapy stuff: 69 | .scrapy 70 | 71 | # Sphinx documentation 72 | docs/_build/ 73 | 74 | # PyBuilder 75 | .pybuilder/ 76 | target/ 77 | 78 | # Jupyter Notebook 79 | .ipynb_checkpoints 80 | 81 | # IPython 82 | profile_default/ 83 | ipython_config.py 84 | 85 | # pyenv 86 | # For a library or package, you might want to ignore these files since the code is 87 | # intended to run in multiple environments; otherwise, check them in: 88 | # .python-version 89 | 90 | # pipenv 91 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. 92 | # However, in case of collaboration, if having platform-specific dependencies or dependencies 93 | # having no cross-platform support, pipenv may install dependencies that don't work, or not 94 | # install all needed dependencies. 95 | #Pipfile.lock 96 | 97 | # poetry 98 | # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. 99 | # This is especially recommended for binary packages to ensure reproducibility, and is more 100 | # commonly ignored for libraries. 101 | # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control 102 | #poetry.lock 103 | 104 | # pdm 105 | # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. 106 | #pdm.lock 107 | # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it 108 | # in version control. 109 | # https://pdm.fming.dev/#use-with-ide 110 | .pdm.toml 111 | 112 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm 113 | __pypackages__/ 114 | 115 | # Celery stuff 116 | celerybeat-schedule 117 | celerybeat.pid 118 | 119 | # SageMath parsed files 120 | *.sage.py 121 | 122 | # Environments 123 | .env 124 | .venv 125 | env/ 126 | venv/ 127 | ENV/ 128 | env.bak/ 129 | venv.bak/ 130 | 131 | # Spyder project settings 132 | .spyderproject 133 | .spyproject 134 | 135 | # Rope project settings 136 | .ropeproject 137 | 138 | # mkdocs documentation 139 | /site 140 | 141 | # mypy 142 | .mypy_cache/ 143 | .dmypy.json 144 | dmypy.json 145 | 146 | # Pyre type checker 147 | .pyre/ 148 | 149 | # pytype static type analyzer 150 | .pytype/ 151 | 152 | # Cython debug symbols 153 | cython_debug/ 154 | 155 | # PyCharm 156 | # JetBrains specific template is maintained in a separate JetBrains.gitignore that can 157 | # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore 158 | # and can be added to the global gitignore or merged into this file. For a more nuclear 159 | # option (not recommended) you can uncomment the following to ignore the entire idea folder. 160 | #.idea/ 161 | 162 | /.vscode/* 163 | 164 | *.cmd 165 | *.bat 166 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2024 Linwei 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # vim-color-export 2 | 3 | Export current colorscheme in traditional Vim color format: 4 | 5 | 1) Can export NeoVim dedicated colors to Vim. 6 | 2) Can export GUI colors to terminal 256 colors format. 7 | 8 | 9 | ## Install 10 | 11 | vim-plug: 12 | 13 | ```VimL 14 | Plug 'skywind3000/vim-color-export' 15 | ``` 16 | 17 | lazy: 18 | 19 | ```lua 20 | { 21 | 'skywind3000/vim-color-export', 22 | config = function () { 23 | vim.g.color_export_all = 0 24 | vim.g.color_export_extra = {'GitGutterAdd', 'GitGutterChange', 'GitGutterDelete'} 25 | vim.g.color_export_convert = 1 26 | }, 27 | }, 28 | ``` 29 | 30 | ## Usage 31 | 32 | Export current colorscheme to "tokyonight.vim" : 33 | 34 | ```VimL 35 | :ColorExport ~/.vim/colors/tokyonight.vim 36 | ``` 37 | 38 | and you can use 'tokyonight' in Vim, like this: 39 | 40 | ![](https://skywind3000.github.io/images/p/colors/tokyonight.png) 41 | 42 | 43 | 44 | ## Options 45 | 46 | #### g:color_export_all 47 | 48 | Default to 0, set to 1 to export all highlight groups. 49 | 50 | #### g:color_export_extra 51 | 52 | Default to an empty list, a list of extra highlight groups to export (when g:color_export_all is `0`): 53 | 54 | ```VimL 55 | let g:color_export_extra = ['GitGutterAdd', 'GitGutterChange', 'GitGutterDelete', 'GitGutterChangeDelete'] 56 | ``` 57 | 58 | #### g:color_export_convert 59 | 60 | Convert gui colors to cterm colors, make current colorscheme usable in any 256-colors terminal without `:set termguicolors`. 61 | 62 | 63 | ## Credit 64 | 65 | Related project: 66 | 67 | - [vim-color-patch](https://github.com/skywind3000/vim-color-patch): Load colorscheme patch script automatically after ":color xxx" command !! 68 | 69 | -------------------------------------------------------------------------------- /autoload/colorexp/colors.vim: -------------------------------------------------------------------------------- 1 | "====================================================================== 2 | " 3 | " colors.vim - 4 | " 5 | " Created by skywind on 2024/02/01 6 | " Last Modified: 2024/03/30 02:36 7 | " 8 | "====================================================================== 9 | 10 | "---------------------------------------------------------------------- 11 | " internal 12 | "---------------------------------------------------------------------- 13 | let s:default_fg = 'NONE' 14 | let s:default_bg = 'NONE' 15 | 16 | 17 | "---------------------------------------------------------------------- 18 | " gui_to_term 19 | "---------------------------------------------------------------------- 20 | function! s:gui_to_cterm(color) abort 21 | let cc = a:color 22 | if cc == '' 23 | return 'NONE' 24 | elseif cc == 'NONE' 25 | return 'NONE' 26 | elseif cc == 'fg' 27 | return s:default_fg 28 | elseif cc == 'bg' 29 | return s:default_bg 30 | endif 31 | return colorexp#palette#name2index(cc) 32 | endfunc 33 | 34 | 35 | "---------------------------------------------------------------------- 36 | " dump style 37 | "---------------------------------------------------------------------- 38 | function! colorexp#colors#dump_style(hid, mode) 39 | let hid = (type(a:hid) == 0)? (a:hid) : hlID(a:hid) 40 | let t = ['underline', 'undercurl', 'reverse', 'inverse'] 41 | let t += ['italic', 'bold', 'standout'] 42 | call filter(t, 'synIDattr(hid, v:val, a:mode)') 43 | let r = empty(t)? 'NONE' : join(t, ',') 44 | return r 45 | endfunc 46 | 47 | 48 | "---------------------------------------------------------------------- 49 | " dump highlight group 50 | "---------------------------------------------------------------------- 51 | function! colorexp#colors#dump_highlight(hid, gui2term) abort 52 | let hid = (type(a:hid) == 0)? (a:hid) : hlID(a:hid) 53 | let name = synIDattr(hid, 'name') 54 | if !hlexists(name) 55 | return '' 56 | endif 57 | let link = synIDtrans(hid) 58 | if hid != link 59 | let linkname = synIDattr(link, 'name') 60 | return printf("hi link %s %s", name, linkname) 61 | endif 62 | let part = [] 63 | let gui = colorexp#colors#dump_style(hid, 'gui') 64 | let term = colorexp#colors#dump_style(hid, 'term') 65 | let cterm = colorexp#colors#dump_style(hid, 'cterm') 66 | if cterm == '' || a:gui2term 67 | let cterm = gui 68 | endif 69 | if gui != '' 70 | let part += ['gui=' .. gui] 71 | endif 72 | if term != '' 73 | let part += ['term=' .. term] 74 | endif 75 | if cterm != '' 76 | let part += ['cterm=' .. cterm] 77 | endif 78 | let guifg = synIDattr(hid, 'fg#', 'gui') 79 | let guibg = synIDattr(hid, 'bg#', 'gui') 80 | let guisp = synIDattr(hid, 'sp#', 'gui') 81 | let ctermfg = synIDattr(hid, 'fg', 'cterm') 82 | let ctermbg = synIDattr(hid, 'bg', 'cterm') 83 | if a:gui2term 84 | let ctermfg = '' 85 | let ctermbg = '' 86 | endif 87 | if ctermfg == '' 88 | let ctermfg = s:gui_to_cterm(guifg) 89 | endif 90 | if ctermbg == '' 91 | let ctermbg = s:gui_to_cterm(guibg) 92 | endif 93 | let guifg = (guifg == '')? 'NONE' : guifg 94 | let guibg = (guibg == '')? 'NONE' : guibg 95 | let fmt = 'guifg=%s guibg=%s ctermfg=%s ctermbg=%s' 96 | let part += [printf(fmt, guifg, guibg, ctermfg, ctermbg)] 97 | if guisp != '' 98 | let part += ['guisp=' .. guisp] 99 | endif 100 | if gui == 'NONE' && term == 'NONE' && cterm == 'NONE' 101 | if guifg == 'NONE' && guibg == 'NONE' && ctermfg == 'NONE' 102 | if ctermbg == 'NONE' && guisp == '' 103 | return printf('hi clear %s', name) 104 | endif 105 | endif 106 | endif 107 | return printf('hi %s %s', name, join(part, ' ')) 108 | endfunc 109 | 110 | 111 | "---------------------------------------------------------------------- 112 | " update normal 113 | "---------------------------------------------------------------------- 114 | function! colorexp#colors#init() 115 | if hlexists('Normal') 116 | let xid = hlID('Normal') 117 | let link = synIDtrans(xid) 118 | while xid != link 119 | let xid = link 120 | let link = synIDtrans(xid) 121 | endwhile 122 | let bg = synIDattr(xid, 'bg#', 'gui') 123 | let fg = synIDattr(xid, 'fg#', 'gui') 124 | let s:default_fg = colorexp#palette#name2index(fg) 125 | let s:default_bg = colorexp#palette#name2index(bg) 126 | endif 127 | endfunc 128 | 129 | 130 | "---------------------------------------------------------------------- 131 | " real_highlight 132 | "---------------------------------------------------------------------- 133 | function! colorexp#colors#real_highlight(hid, gui2term) 134 | let hid = (type(a:hid) == 0)? (a:hid) : hlID(a:hid) 135 | let name = synIDattr(hid, 'name') 136 | if !hlexists(name) 137 | return '' 138 | endif 139 | let link = synIDtrans(hid) 140 | while hid != link 141 | let hid = link 142 | let link = synIDtrans(hid) 143 | endwhile 144 | let script = colorexp#colors#dump_highlight(hid, a:gui2term) 145 | if script =~ '^hi clear' 146 | if name == 'Normal' 147 | return 'hi! clear Normal' 148 | endif 149 | let script = colorexp#colors#real_highlight('Normal', a:gui2term) 150 | endif 151 | let part = split(script, ' ')[2:] 152 | return printf('hi! %s %s', name, join(part, ' ')) 153 | endfunc 154 | 155 | 156 | "---------------------------------------------------------------------- 157 | " convert to term 158 | "---------------------------------------------------------------------- 159 | function! colorexp#colors#list_highlight(gui2term) 160 | let hid = 1 161 | let output = [] 162 | let s:default_bg = 'NONE' 163 | let s:default_fg = 'NONE' 164 | call colorexp#colors#init() 165 | while 1 166 | let hln = synIDattr(hid, 'name') 167 | if !hlexists(hln) 168 | break 169 | endif 170 | let t = colorexp#colors#dump_highlight(hid, a:gui2term) 171 | let output += [t] 172 | let hid += 1 173 | endwhile 174 | return output 175 | endfunc 176 | 177 | 178 | "---------------------------------------------------------------------- 179 | " list color names 180 | "---------------------------------------------------------------------- 181 | function! colorexp#colors#list_names() 182 | let hid = 1 183 | let output = [] 184 | while 1 185 | let hln = synIDattr(hid, 'name') 186 | if !hlexists(hln) 187 | break 188 | endif 189 | let output += [hln] 190 | let hid += 1 191 | endwhile 192 | return output 193 | endfunc 194 | 195 | 196 | "---------------------------------------------------------------------- 197 | " convert_gui_color 198 | "---------------------------------------------------------------------- 199 | function! colorexp#colors#convert_gui_color() 200 | let script = colorexp#colors#list_highlight(1) 201 | exec 'hi clear' 202 | for n in script 203 | exec n 204 | endfor 205 | endfunc 206 | 207 | 208 | 209 | -------------------------------------------------------------------------------- /autoload/colorexp/export.vim: -------------------------------------------------------------------------------- 1 | "====================================================================== 2 | " 3 | " export.vim - 4 | " 5 | " Created by skywind on 2024/02/01 6 | " Last Modified: 2024/02/02 04:22 7 | " 8 | "====================================================================== 9 | 10 | 11 | "---------------------------------------------------------------------- 12 | " list highlight 13 | "---------------------------------------------------------------------- 14 | function! colorexp#export#list_highlight() 15 | let colorexp#palette#number = get(g:, 'color_palette_number', 256) 16 | let output = [] 17 | let names = colorexp#names#collect() 18 | let convert = get(g:, 'color_export_convert', 1) 19 | call colorexp#colors#init() 20 | for name in names 21 | if hlexists(name) 22 | let hid = hlID(name) 23 | let t = colorexp#colors#dump_highlight(hid, convert) 24 | if stridx(t, '@') < 0 25 | let output += [t] 26 | endif 27 | endif 28 | endfor 29 | return output 30 | endfunc 31 | 32 | " call colorexp#export#list_highlight() 33 | 34 | 35 | "---------------------------------------------------------------------- 36 | " proceed 37 | "---------------------------------------------------------------------- 38 | function! colorexp#export#proceed(name) 39 | let cname = get(g:, 'colors_name', 'default') 40 | let tname = fnamemodify(a:name, ':t:r') 41 | let output = [] 42 | let output += [printf('set background=%s', &background)] 43 | let output += ['hi clear'] 44 | let output += [''] 45 | let output += [printf('let g:colors_name = "%s"', tname)] 46 | let output += [''] 47 | let output += colorexp#export#list_highlight() 48 | call writefile(output, a:name) 49 | endfunc 50 | 51 | 52 | 53 | -------------------------------------------------------------------------------- /autoload/colorexp/names.vim: -------------------------------------------------------------------------------- 1 | "====================================================================== 2 | " 3 | " names.vim - 4 | " 5 | " Created by skywind on 2024/01/31 6 | " Last Modified: 2024/02/01 22:48 7 | " 8 | "====================================================================== 9 | 10 | 11 | "---------------------------------------------------------------------- 12 | " native names 13 | "---------------------------------------------------------------------- 14 | let s:native_names = [ 15 | \ 'Added', 'Boolean', 'Changed', 'Character', 'ColorColumn', 'Comment', 16 | \ 'Conceal', 'Conditional', 'Constant', 'CurSearch', 'Cursor', 17 | \ 'CursorColumn', 'CursorIM', 'CursorLine', 'CursorLineFold', 18 | \ 'CursorLineNr', 'CursorLineSign', 'Debug', 'Define', 'Delimiter', 19 | \ 'DiffAdd', 'DiffChange', 'DiffDelete', 'DiffText', 'Directory', 20 | \ 'EndOfBuffer', 'Error', 'ErrorMsg', 'Exception', 'Float', 21 | \ 'FoldColumn', 'Folded', 'Function', 'Identifier', 'Ignore', 22 | \ 'IncSearch', 'Include', 'Keyword', 'Label', 'LineNr', 'LineNrAbove', 23 | \ 'LineNrBelow', 'Macro', 'MatchParen', 'MessageWindow', 'ModeMsg', 24 | \ 'MoreMsg', 'NonText', 'Normal', 'Number', 'Operator', 'Pmenu', 25 | \ 'PmenuExtra', 'PmenuExtraSel', 'PmenuKind', 'PmenuKindSel', 26 | \ 'PmenuMatch', 'PmenuMatchSel', 'PmenuSbar', 'PmenuSel', 'PmenuThumb', 27 | \ 'PopupNotificatio', 28 | \ 'PreCondit', 'PreProc', 'Question', 'QuickFixLine', 'Removed', 29 | \ 'Repeat', 'Search', 'SignColumn', 'Special', 'SpecialChar', 30 | \ 'SpecialComment', 'SpecialKey', 'SpellBad', 'SpellCap', 'SpellLocal', 31 | \ 'SpellRare', 'Statement', 'StatusLine', 'StatusLineNC', 32 | \ 'StatusLineTerm', 'StatusLineTermNC', 'StorageClass', 'String', 33 | \ 'Structure', 'TabLine', 'TabLineFill', 'TabLineSel', 'Tag', 34 | \ 'Terminal', 'Title', 'Todo', 'ToolbarButton', 'ToolbarLine', 'Type', 35 | \ 'Typedef', 'Underlined', 'VertSplit', 'Visual', 'VisualNOS', 36 | \ 'WarningMsg', 'WildMenu', 'lCursor', 37 | \ ] 38 | 39 | 40 | "---------------------------------------------------------------------- 41 | " extend_link 42 | "---------------------------------------------------------------------- 43 | function! colorexp#names#extend_link(list) abort 44 | let list = deepcopy(a:list) 45 | let dict = {} 46 | for name in list 47 | let dict[name] = 1 48 | endfor 49 | let index = 0 50 | while index < len(list) 51 | let name = list[index] 52 | if hlexists(name) 53 | let hid = hlID(name) 54 | let link = synIDtrans(hid) 55 | " echo printf("name=%s hid=%d link=%d", name, hid, link) 56 | if hid != link 57 | let linkname = synIDattr(link, 'name') 58 | if !has_key(dict, linkname) 59 | let dict[linkname] = 1 60 | let list += [linkname] 61 | endif 62 | endif 63 | endif 64 | let index += 1 65 | endwhile 66 | let output = [] 67 | let dict = {} 68 | for name in list 69 | if !has_key(dict, name) 70 | let output += [name] 71 | let dict[name] = 1 72 | endif 73 | endfor 74 | return output 75 | endfunc 76 | 77 | 78 | "---------------------------------------------------------------------- 79 | " collect required names 80 | "---------------------------------------------------------------------- 81 | function! colorexp#names#collect() abort 82 | let candidate = [] 83 | let output = [] 84 | if get(g:, 'color_export_all', 0) 85 | let hid = 1 86 | while 1 87 | let name = synIDattr(hid, 'name') 88 | if !hlexists(name) 89 | break 90 | endif 91 | if stridx(name, '@') < 0 92 | let candidate += [name] 93 | endif 94 | let hid += 1 95 | endwhile 96 | else 97 | let extra = [] 98 | if exists('g:color_export_extra') 99 | if type(g:color_export_extra) == type([]) 100 | let extra = g:color_export_extra 101 | elseif type(g:color_export_extra) == type('') 102 | let extra = split(g:color_export_extra, ',') 103 | endif 104 | endif 105 | let candidate = colorexp#names#extend_link(s:native_names + extra) 106 | endif 107 | for name in candidate 108 | if stridx(name, '@') < 0 109 | let output += [name] 110 | endif 111 | endfor 112 | return output 113 | endfunc 114 | 115 | 116 | "---------------------------------------------------------------------- 117 | " 118 | "---------------------------------------------------------------------- 119 | function! colorexp#names#test1() abort 120 | let list = ['CursorLine', 'CursorLineSign', 'CursorLineFold', 'QuickFixLine'] 121 | let newlist = colorexp#names#extend_link(list) 122 | for name in newlist 123 | echo name 124 | endfor 125 | endfunc 126 | 127 | function! colorexp#names#test2() 128 | let list1 = s:native_names 129 | let list2 = colorexp#names#extend_link(list1) 130 | echo printf("%d %d", len(list1), len(list2)) 131 | endfunc 132 | 133 | " call colorexp#names#test1() 134 | 135 | 136 | -------------------------------------------------------------------------------- /autoload/colorexp/palette.vim: -------------------------------------------------------------------------------- 1 | "====================================================================== 2 | " 3 | " palette.vim - 4 | " 5 | " Created by skywind on 2021/12/23 6 | " Last Modified: 2022/09/25 01:31 7 | " 8 | "====================================================================== 9 | 10 | " vim: set ts=4 sw=4 tw=78 noet : 11 | 12 | 13 | "---------------------------------------------------------------------- 14 | " terminal palette of 256 colors 15 | "---------------------------------------------------------------------- 16 | let g:colorexp#palette#colors = [ 17 | \ { 'color': 0, 'name': 'Black', 'hex': '#000000' }, 18 | \ { 'color': 1, 'name': 'Maroon', 'hex': '#800000' }, 19 | \ { 'color': 2, 'name': 'Green', 'hex': '#008000' }, 20 | \ { 'color': 3, 'name': 'Olive', 'hex': '#808000' }, 21 | \ { 'color': 4, 'name': 'Navy', 'hex': '#000080' }, 22 | \ { 'color': 5, 'name': 'Purple', 'hex': '#800080' }, 23 | \ { 'color': 6, 'name': 'Teal', 'hex': '#008080' }, 24 | \ { 'color': 7, 'name': 'Silver', 'hex': '#c0c0c0' }, 25 | \ { 'color': 8, 'name': 'Grey', 'hex': '#808080' }, 26 | \ { 'color': 9, 'name': 'Red', 'hex': '#ff0000' }, 27 | \ { 'color': 10, 'name': 'Lime', 'hex': '#00ff00' }, 28 | \ { 'color': 11, 'name': 'Yellow', 'hex': '#ffff00' }, 29 | \ { 'color': 12, 'name': 'Blue', 'hex': '#0000ff' }, 30 | \ { 'color': 13, 'name': 'Fuchsia', 'hex': '#ff00ff' }, 31 | \ { 'color': 14, 'name': 'Aqua', 'hex': '#00ffff' }, 32 | \ { 'color': 15, 'name': 'White', 'hex': '#ffffff' }, 33 | \ { 'color': 16, 'name': 'Grey0', 'hex': '#000000' }, 34 | \ { 'color': 17, 'name': 'NavyBlue', 'hex': '#00005f' }, 35 | \ { 'color': 18, 'name': 'DarkBlue', 'hex': '#000087' }, 36 | \ { 'color': 19, 'name': 'Blue3', 'hex': '#0000af' }, 37 | \ { 'color': 20, 'name': 'Blue3', 'hex': '#0000d7' }, 38 | \ { 'color': 21, 'name': 'Blue1', 'hex': '#0000ff' }, 39 | \ { 'color': 22, 'name': 'DarkGreen', 'hex': '#005f00' }, 40 | \ { 'color': 23, 'name': 'DeepSkyBlue4', 'hex': '#005f5f' }, 41 | \ { 'color': 24, 'name': 'DeepSkyBlue4', 'hex': '#005f87' }, 42 | \ { 'color': 25, 'name': 'DeepSkyBlue4', 'hex': '#005faf' }, 43 | \ { 'color': 26, 'name': 'DodgerBlue3', 'hex': '#005fd7' }, 44 | \ { 'color': 27, 'name': 'DodgerBlue2', 'hex': '#005fff' }, 45 | \ { 'color': 28, 'name': 'Green4', 'hex': '#008700' }, 46 | \ { 'color': 29, 'name': 'SpringGreen4', 'hex': '#00875f' }, 47 | \ { 'color': 30, 'name': 'Turquoise4', 'hex': '#008787' }, 48 | \ { 'color': 31, 'name': 'DeepSkyBlue3', 'hex': '#0087af' }, 49 | \ { 'color': 32, 'name': 'DeepSkyBlue3', 'hex': '#0087d7' }, 50 | \ { 'color': 33, 'name': 'DodgerBlue1', 'hex': '#0087ff' }, 51 | \ { 'color': 34, 'name': 'Green3', 'hex': '#00af00' }, 52 | \ { 'color': 35, 'name': 'SpringGreen3', 'hex': '#00af5f' }, 53 | \ { 'color': 36, 'name': 'DarkCyan', 'hex': '#00af87' }, 54 | \ { 'color': 37, 'name': 'LightSeaGreen', 'hex': '#00afaf' }, 55 | \ { 'color': 38, 'name': 'DeepSkyBlue2', 'hex': '#00afd7' }, 56 | \ { 'color': 39, 'name': 'DeepSkyBlue1', 'hex': '#00afff' }, 57 | \ { 'color': 40, 'name': 'Green3', 'hex': '#00d700' }, 58 | \ { 'color': 41, 'name': 'SpringGreen3', 'hex': '#00d75f' }, 59 | \ { 'color': 42, 'name': 'SpringGreen2', 'hex': '#00d787' }, 60 | \ { 'color': 43, 'name': 'Cyan3', 'hex': '#00d7af' }, 61 | \ { 'color': 44, 'name': 'DarkTurquoise', 'hex': '#00d7d7' }, 62 | \ { 'color': 45, 'name': 'Turquoise2', 'hex': '#00d7ff' }, 63 | \ { 'color': 46, 'name': 'Green1', 'hex': '#00ff00' }, 64 | \ { 'color': 47, 'name': 'SpringGreen2', 'hex': '#00ff5f' }, 65 | \ { 'color': 48, 'name': 'SpringGreen1', 'hex': '#00ff87' }, 66 | \ { 'color': 49, 'name': 'MediumSpringGreen', 'hex': '#00ffaf' }, 67 | \ { 'color': 50, 'name': 'Cyan2', 'hex': '#00ffd7' }, 68 | \ { 'color': 51, 'name': 'Cyan1', 'hex': '#00ffff' }, 69 | \ { 'color': 52, 'name': 'DarkRed', 'hex': '#5f0000' }, 70 | \ { 'color': 53, 'name': 'DeepPink4', 'hex': '#5f005f' }, 71 | \ { 'color': 54, 'name': 'Purple4', 'hex': '#5f0087' }, 72 | \ { 'color': 55, 'name': 'Purple4', 'hex': '#5f00af' }, 73 | \ { 'color': 56, 'name': 'Purple3', 'hex': '#5f00d7' }, 74 | \ { 'color': 57, 'name': 'BlueViolet', 'hex': '#5f00ff' }, 75 | \ { 'color': 58, 'name': 'Orange4', 'hex': '#5f5f00' }, 76 | \ { 'color': 59, 'name': 'Grey37', 'hex': '#5f5f5f' }, 77 | \ { 'color': 60, 'name': 'MediumPurple4', 'hex': '#5f5f87' }, 78 | \ { 'color': 61, 'name': 'SlateBlue3', 'hex': '#5f5faf' }, 79 | \ { 'color': 62, 'name': 'SlateBlue3', 'hex': '#5f5fd7' }, 80 | \ { 'color': 63, 'name': 'RoyalBlue1', 'hex': '#5f5fff' }, 81 | \ { 'color': 64, 'name': 'Chartreuse4', 'hex': '#5f8700' }, 82 | \ { 'color': 65, 'name': 'DarkSeaGreen4', 'hex': '#5f875f' }, 83 | \ { 'color': 66, 'name': 'PaleTurquoise4', 'hex': '#5f8787' }, 84 | \ { 'color': 67, 'name': 'SteelBlue', 'hex': '#5f87af' }, 85 | \ { 'color': 68, 'name': 'SteelBlue3', 'hex': '#5f87d7' }, 86 | \ { 'color': 69, 'name': 'CornflowerBlue', 'hex': '#5f87ff' }, 87 | \ { 'color': 70, 'name': 'Chartreuse3', 'hex': '#5faf00' }, 88 | \ { 'color': 71, 'name': 'DarkSeaGreen4', 'hex': '#5faf5f' }, 89 | \ { 'color': 72, 'name': 'CadetBlue', 'hex': '#5faf87' }, 90 | \ { 'color': 73, 'name': 'CadetBlue', 'hex': '#5fafaf' }, 91 | \ { 'color': 74, 'name': 'SkyBlue3', 'hex': '#5fafd7' }, 92 | \ { 'color': 75, 'name': 'SteelBlue1', 'hex': '#5fafff' }, 93 | \ { 'color': 76, 'name': 'Chartreuse3', 'hex': '#5fd700' }, 94 | \ { 'color': 77, 'name': 'PaleGreen3', 'hex': '#5fd75f' }, 95 | \ { 'color': 78, 'name': 'SeaGreen3', 'hex': '#5fd787' }, 96 | \ { 'color': 79, 'name': 'Aquamarine3', 'hex': '#5fd7af' }, 97 | \ { 'color': 80, 'name': 'MediumTurquoise', 'hex': '#5fd7d7' }, 98 | \ { 'color': 81, 'name': 'SteelBlue1', 'hex': '#5fd7ff' }, 99 | \ { 'color': 82, 'name': 'Chartreuse2', 'hex': '#5fff00' }, 100 | \ { 'color': 83, 'name': 'SeaGreen2', 'hex': '#5fff5f' }, 101 | \ { 'color': 84, 'name': 'SeaGreen1', 'hex': '#5fff87' }, 102 | \ { 'color': 85, 'name': 'SeaGreen1', 'hex': '#5fffaf' }, 103 | \ { 'color': 86, 'name': 'Aquamarine1', 'hex': '#5fffd7' }, 104 | \ { 'color': 87, 'name': 'DarkSlateGray2', 'hex': '#5fffff' }, 105 | \ { 'color': 88, 'name': 'DarkRed', 'hex': '#870000' }, 106 | \ { 'color': 89, 'name': 'DeepPink4', 'hex': '#87005f' }, 107 | \ { 'color': 90, 'name': 'DarkMagenta', 'hex': '#870087' }, 108 | \ { 'color': 91, 'name': 'DarkMagenta', 'hex': '#8700af' }, 109 | \ { 'color': 92, 'name': 'DarkViolet', 'hex': '#8700d7' }, 110 | \ { 'color': 93, 'name': 'Purple', 'hex': '#8700ff' }, 111 | \ { 'color': 94, 'name': 'Orange4', 'hex': '#875f00' }, 112 | \ { 'color': 95, 'name': 'LightPink4', 'hex': '#875f5f' }, 113 | \ { 'color': 96, 'name': 'Plum4', 'hex': '#875f87' }, 114 | \ { 'color': 97, 'name': 'MediumPurple3', 'hex': '#875faf' }, 115 | \ { 'color': 98, 'name': 'MediumPurple3', 'hex': '#875fd7' }, 116 | \ { 'color': 99, 'name': 'SlateBlue1', 'hex': '#875fff' }, 117 | \ { 'color': 100, 'name': 'Yellow4', 'hex': '#878700' }, 118 | \ { 'color': 101, 'name': 'Wheat4', 'hex': '#87875f' }, 119 | \ { 'color': 102, 'name': 'Grey53', 'hex': '#878787' }, 120 | \ { 'color': 103, 'name': 'LightSlateGrey', 'hex': '#8787af' }, 121 | \ { 'color': 104, 'name': 'MediumPurple', 'hex': '#8787d7' }, 122 | \ { 'color': 105, 'name': 'LightSlateBlue', 'hex': '#8787ff' }, 123 | \ { 'color': 106, 'name': 'Yellow4', 'hex': '#87af00' }, 124 | \ { 'color': 107, 'name': 'DarkOliveGreen3', 'hex': '#87af5f' }, 125 | \ { 'color': 108, 'name': 'DarkSeaGreen', 'hex': '#87af87' }, 126 | \ { 'color': 109, 'name': 'LightSkyBlue3', 'hex': '#87afaf' }, 127 | \ { 'color': 110, 'name': 'LightSkyBlue3', 'hex': '#87afd7' }, 128 | \ { 'color': 111, 'name': 'SkyBlue2', 'hex': '#87afff' }, 129 | \ { 'color': 112, 'name': 'Chartreuse2', 'hex': '#87d700' }, 130 | \ { 'color': 113, 'name': 'DarkOliveGreen3', 'hex': '#87d75f' }, 131 | \ { 'color': 114, 'name': 'PaleGreen3', 'hex': '#87d787' }, 132 | \ { 'color': 115, 'name': 'DarkSeaGreen3', 'hex': '#87d7af' }, 133 | \ { 'color': 116, 'name': 'DarkSlateGray3', 'hex': '#87d7d7' }, 134 | \ { 'color': 117, 'name': 'SkyBlue1', 'hex': '#87d7ff' }, 135 | \ { 'color': 118, 'name': 'Chartreuse1', 'hex': '#87ff00' }, 136 | \ { 'color': 119, 'name': 'LightGreen', 'hex': '#87ff5f' }, 137 | \ { 'color': 120, 'name': 'LightGreen', 'hex': '#87ff87' }, 138 | \ { 'color': 121, 'name': 'PaleGreen1', 'hex': '#87ffaf' }, 139 | \ { 'color': 122, 'name': 'Aquamarine1', 'hex': '#87ffd7' }, 140 | \ { 'color': 123, 'name': 'DarkSlateGray1', 'hex': '#87ffff' }, 141 | \ { 'color': 124, 'name': 'Red3', 'hex': '#af0000' }, 142 | \ { 'color': 125, 'name': 'DeepPink4', 'hex': '#af005f' }, 143 | \ { 'color': 126, 'name': 'MediumVioletRed', 'hex': '#af0087' }, 144 | \ { 'color': 127, 'name': 'Magenta3', 'hex': '#af00af' }, 145 | \ { 'color': 128, 'name': 'DarkViolet', 'hex': '#af00d7' }, 146 | \ { 'color': 129, 'name': 'Purple', 'hex': '#af00ff' }, 147 | \ { 'color': 130, 'name': 'DarkOrange3', 'hex': '#af5f00' }, 148 | \ { 'color': 131, 'name': 'IndianRed', 'hex': '#af5f5f' }, 149 | \ { 'color': 132, 'name': 'HotPink3', 'hex': '#af5f87' }, 150 | \ { 'color': 133, 'name': 'MediumOrchid3', 'hex': '#af5faf' }, 151 | \ { 'color': 134, 'name': 'MediumOrchid', 'hex': '#af5fd7' }, 152 | \ { 'color': 135, 'name': 'MediumPurple2', 'hex': '#af5fff' }, 153 | \ { 'color': 136, 'name': 'DarkGoldenrod', 'hex': '#af8700' }, 154 | \ { 'color': 137, 'name': 'LightSalmon3', 'hex': '#af875f' }, 155 | \ { 'color': 138, 'name': 'RosyBrown', 'hex': '#af8787' }, 156 | \ { 'color': 139, 'name': 'Grey63', 'hex': '#af87af' }, 157 | \ { 'color': 140, 'name': 'MediumPurple2', 'hex': '#af87d7' }, 158 | \ { 'color': 141, 'name': 'MediumPurple1', 'hex': '#af87ff' }, 159 | \ { 'color': 142, 'name': 'Gold3', 'hex': '#afaf00' }, 160 | \ { 'color': 143, 'name': 'DarkKhaki', 'hex': '#afaf5f' }, 161 | \ { 'color': 144, 'name': 'NavajoWhite3', 'hex': '#afaf87' }, 162 | \ { 'color': 145, 'name': 'Grey69', 'hex': '#afafaf' }, 163 | \ { 'color': 146, 'name': 'LightSteelBlue3', 'hex': '#afafd7' }, 164 | \ { 'color': 147, 'name': 'LightSteelBlue', 'hex': '#afafff' }, 165 | \ { 'color': 148, 'name': 'Yellow3', 'hex': '#afd700' }, 166 | \ { 'color': 149, 'name': 'DarkOliveGreen3', 'hex': '#afd75f' }, 167 | \ { 'color': 150, 'name': 'DarkSeaGreen3', 'hex': '#afd787' }, 168 | \ { 'color': 151, 'name': 'DarkSeaGreen2', 'hex': '#afd7af' }, 169 | \ { 'color': 152, 'name': 'LightCyan3', 'hex': '#afd7d7' }, 170 | \ { 'color': 153, 'name': 'LightSkyBlue1', 'hex': '#afd7ff' }, 171 | \ { 'color': 154, 'name': 'GreenYellow', 'hex': '#afff00' }, 172 | \ { 'color': 155, 'name': 'DarkOliveGreen2', 'hex': '#afff5f' }, 173 | \ { 'color': 156, 'name': 'PaleGreen1', 'hex': '#afff87' }, 174 | \ { 'color': 157, 'name': 'DarkSeaGreen2', 'hex': '#afffaf' }, 175 | \ { 'color': 158, 'name': 'DarkSeaGreen1', 'hex': '#afffd7' }, 176 | \ { 'color': 159, 'name': 'PaleTurquoise1', 'hex': '#afffff' }, 177 | \ { 'color': 160, 'name': 'Red3', 'hex': '#d70000' }, 178 | \ { 'color': 161, 'name': 'DeepPink3', 'hex': '#d7005f' }, 179 | \ { 'color': 162, 'name': 'DeepPink3', 'hex': '#d70087' }, 180 | \ { 'color': 163, 'name': 'Magenta3', 'hex': '#d700af' }, 181 | \ { 'color': 164, 'name': 'Magenta3', 'hex': '#d700d7' }, 182 | \ { 'color': 165, 'name': 'Magenta2', 'hex': '#d700ff' }, 183 | \ { 'color': 166, 'name': 'DarkOrange3', 'hex': '#d75f00' }, 184 | \ { 'color': 167, 'name': 'IndianRed', 'hex': '#d75f5f' }, 185 | \ { 'color': 168, 'name': 'HotPink3', 'hex': '#d75f87' }, 186 | \ { 'color': 169, 'name': 'HotPink2', 'hex': '#d75faf' }, 187 | \ { 'color': 170, 'name': 'Orchid', 'hex': '#d75fd7' }, 188 | \ { 'color': 171, 'name': 'MediumOrchid1', 'hex': '#d75fff' }, 189 | \ { 'color': 172, 'name': 'Orange3', 'hex': '#d78700' }, 190 | \ { 'color': 173, 'name': 'LightSalmon3', 'hex': '#d7875f' }, 191 | \ { 'color': 174, 'name': 'LightPink3', 'hex': '#d78787' }, 192 | \ { 'color': 175, 'name': 'Pink3', 'hex': '#d787af' }, 193 | \ { 'color': 176, 'name': 'Plum3', 'hex': '#d787d7' }, 194 | \ { 'color': 177, 'name': 'Violet', 'hex': '#d787ff' }, 195 | \ { 'color': 178, 'name': 'Gold3', 'hex': '#d7af00' }, 196 | \ { 'color': 179, 'name': 'LightGoldenrod3', 'hex': '#d7af5f' }, 197 | \ { 'color': 180, 'name': 'Tan', 'hex': '#d7af87' }, 198 | \ { 'color': 181, 'name': 'MistyRose3', 'hex': '#d7afaf' }, 199 | \ { 'color': 182, 'name': 'Thistle3', 'hex': '#d7afd7' }, 200 | \ { 'color': 183, 'name': 'Plum2', 'hex': '#d7afff' }, 201 | \ { 'color': 184, 'name': 'Yellow3', 'hex': '#d7d700' }, 202 | \ { 'color': 185, 'name': 'Khaki3', 'hex': '#d7d75f' }, 203 | \ { 'color': 186, 'name': 'LightGoldenrod2', 'hex': '#d7d787' }, 204 | \ { 'color': 187, 'name': 'LightYellow3', 'hex': '#d7d7af' }, 205 | \ { 'color': 188, 'name': 'Grey84', 'hex': '#d7d7d7' }, 206 | \ { 'color': 189, 'name': 'LightSteelBlue1', 'hex': '#d7d7ff' }, 207 | \ { 'color': 190, 'name': 'Yellow2', 'hex': '#d7ff00' }, 208 | \ { 'color': 191, 'name': 'DarkOliveGreen1', 'hex': '#d7ff5f' }, 209 | \ { 'color': 192, 'name': 'DarkOliveGreen1', 'hex': '#d7ff87' }, 210 | \ { 'color': 193, 'name': 'DarkSeaGreen1', 'hex': '#d7ffaf' }, 211 | \ { 'color': 194, 'name': 'Honeydew2', 'hex': '#d7ffd7' }, 212 | \ { 'color': 195, 'name': 'LightCyan1', 'hex': '#d7ffff' }, 213 | \ { 'color': 196, 'name': 'Red1', 'hex': '#ff0000' }, 214 | \ { 'color': 197, 'name': 'DeepPink2', 'hex': '#ff005f' }, 215 | \ { 'color': 198, 'name': 'DeepPink1', 'hex': '#ff0087' }, 216 | \ { 'color': 199, 'name': 'DeepPink1', 'hex': '#ff00af' }, 217 | \ { 'color': 200, 'name': 'Magenta2', 'hex': '#ff00d7' }, 218 | \ { 'color': 201, 'name': 'Magenta1', 'hex': '#ff00ff' }, 219 | \ { 'color': 202, 'name': 'OrangeRed1', 'hex': '#ff5f00' }, 220 | \ { 'color': 203, 'name': 'IndianRed1', 'hex': '#ff5f5f' }, 221 | \ { 'color': 204, 'name': 'IndianRed1', 'hex': '#ff5f87' }, 222 | \ { 'color': 205, 'name': 'HotPink', 'hex': '#ff5faf' }, 223 | \ { 'color': 206, 'name': 'HotPink', 'hex': '#ff5fd7' }, 224 | \ { 'color': 207, 'name': 'MediumOrchid1', 'hex': '#ff5fff' }, 225 | \ { 'color': 208, 'name': 'DarkOrange', 'hex': '#ff8700' }, 226 | \ { 'color': 209, 'name': 'Salmon1', 'hex': '#ff875f' }, 227 | \ { 'color': 210, 'name': 'LightCoral', 'hex': '#ff8787' }, 228 | \ { 'color': 211, 'name': 'PaleVioletRed1', 'hex': '#ff87af' }, 229 | \ { 'color': 212, 'name': 'Orchid2', 'hex': '#ff87d7' }, 230 | \ { 'color': 213, 'name': 'Orchid1', 'hex': '#ff87ff' }, 231 | \ { 'color': 214, 'name': 'Orange1', 'hex': '#ffaf00' }, 232 | \ { 'color': 215, 'name': 'SandyBrown', 'hex': '#ffaf5f' }, 233 | \ { 'color': 216, 'name': 'LightSalmon1', 'hex': '#ffaf87' }, 234 | \ { 'color': 217, 'name': 'LightPink1', 'hex': '#ffafaf' }, 235 | \ { 'color': 218, 'name': 'Pink1', 'hex': '#ffafd7' }, 236 | \ { 'color': 219, 'name': 'Plum1', 'hex': '#ffafff' }, 237 | \ { 'color': 220, 'name': 'Gold1', 'hex': '#ffd700' }, 238 | \ { 'color': 221, 'name': 'LightGoldenrod2', 'hex': '#ffd75f' }, 239 | \ { 'color': 222, 'name': 'LightGoldenrod2', 'hex': '#ffd787' }, 240 | \ { 'color': 223, 'name': 'NavajoWhite1', 'hex': '#ffd7af' }, 241 | \ { 'color': 224, 'name': 'MistyRose1', 'hex': '#ffd7d7' }, 242 | \ { 'color': 225, 'name': 'Thistle1', 'hex': '#ffd7ff' }, 243 | \ { 'color': 226, 'name': 'Yellow1', 'hex': '#ffff00' }, 244 | \ { 'color': 227, 'name': 'LightGoldenrod1', 'hex': '#ffff5f' }, 245 | \ { 'color': 228, 'name': 'Khaki1', 'hex': '#ffff87' }, 246 | \ { 'color': 229, 'name': 'Wheat1', 'hex': '#ffffaf' }, 247 | \ { 'color': 230, 'name': 'Cornsilk1', 'hex': '#ffffd7' }, 248 | \ { 'color': 231, 'name': 'Grey100', 'hex': '#ffffff' }, 249 | \ { 'color': 232, 'name': 'Grey3', 'hex': '#080808' }, 250 | \ { 'color': 233, 'name': 'Grey7', 'hex': '#121212' }, 251 | \ { 'color': 234, 'name': 'Grey11', 'hex': '#1c1c1c' }, 252 | \ { 'color': 235, 'name': 'Grey15', 'hex': '#262626' }, 253 | \ { 'color': 236, 'name': 'Grey19', 'hex': '#303030' }, 254 | \ { 'color': 237, 'name': 'Grey23', 'hex': '#3a3a3a' }, 255 | \ { 'color': 238, 'name': 'Grey27', 'hex': '#444444' }, 256 | \ { 'color': 239, 'name': 'Grey30', 'hex': '#4e4e4e' }, 257 | \ { 'color': 240, 'name': 'Grey35', 'hex': '#585858' }, 258 | \ { 'color': 241, 'name': 'Grey39', 'hex': '#626262' }, 259 | \ { 'color': 242, 'name': 'Grey42', 'hex': '#6c6c6c' }, 260 | \ { 'color': 243, 'name': 'Grey46', 'hex': '#767676' }, 261 | \ { 'color': 244, 'name': 'Grey50', 'hex': '#808080' }, 262 | \ { 'color': 245, 'name': 'Grey54', 'hex': '#8a8a8a' }, 263 | \ { 'color': 246, 'name': 'Grey58', 'hex': '#949494' }, 264 | \ { 'color': 247, 'name': 'Grey62', 'hex': '#9e9e9e' }, 265 | \ { 'color': 248, 'name': 'Grey66', 'hex': '#a8a8a8' }, 266 | \ { 'color': 249, 'name': 'Grey70', 'hex': '#b2b2b2' }, 267 | \ { 'color': 250, 'name': 'Grey74', 'hex': '#bcbcbc' }, 268 | \ { 'color': 251, 'name': 'Grey78', 'hex': '#c6c6c6' }, 269 | \ { 'color': 252, 'name': 'Grey82', 'hex': '#d0d0d0' }, 270 | \ { 'color': 253, 'name': 'Grey85', 'hex': '#dadada' }, 271 | \ { 'color': 254, 'name': 'Grey89', 'hex': '#e4e4e4' }, 272 | \ { 'color': 255, 'name': 'Grey93', 'hex': '#eeeeee' }, 273 | \ ] 274 | 275 | 276 | "---------------------------------------------------------------------- 277 | " color index to RGB 278 | "---------------------------------------------------------------------- 279 | let g:colorexp#palette#rgb = [] 280 | let g:colorexp#palette#name = {} 281 | let g:colorexp#palette#number = get(g:, 'color_palette_number', 256) 282 | 283 | let s:palette = [] 284 | let s:matched = {} 285 | let s:names = {} 286 | let s:diff_lookup = repeat([0], 512 * 3) 287 | 288 | for color in g:colorexp#palette#colors 289 | let cc = str2nr(strpart(color.hex, 1), 16) 290 | let r = and(cc / 0x10000, 0xff) 291 | let g = and(cc / 0x100, 0xff) 292 | let b = and(cc, 0xff) 293 | let g:colorexp#palette#rgb += [[r, g, b]] 294 | let s:palette += [[r, g, b]] 295 | let g:colorexp#palette#name[tolower(color.name)] = color.color 296 | let s:names[tolower(color.name)] = color.color 297 | endfor 298 | 299 | 300 | "---------------------------------------------------------------------- 301 | " bestfit color 302 | "---------------------------------------------------------------------- 303 | function! s:bestfit_color(r, g, b, limit) 304 | if s:diff_lookup[0] == 0 305 | for i in range(256) 306 | let k = i * i 307 | let dr = k * 30 * 30 308 | let dg = k * 59 * 59 309 | let db = k * 11 * 11 310 | let s:diff_lookup[ 256 + i] = dr 311 | let s:diff_lookup[ 256 - i] = dr 312 | let s:diff_lookup[ 768 + i] = dg 313 | let s:diff_lookup[ 768 - i] = dg 314 | let s:diff_lookup[1280 + i] = db 315 | let s:diff_lookup[1280 - i] = db 316 | endfor 317 | let s:diff_lookup[0] = 1 318 | endif 319 | let r = (a:r < 256)? (a:r) : 255 320 | let g = (a:g < 256)? (a:g) : 255 321 | let b = (a:b < 256)? (a:b) : 255 322 | let lowest = 0x7fffffff 323 | let bestfit = 0 324 | let index = 0 325 | let limit = (a:limit < 256)? (a:limit) : 256 326 | let palette = s:palette 327 | let lookup = s:diff_lookup 328 | while index < limit 329 | let rgb = palette[index] 330 | let diff = lookup[ 768 + rgb[1] - g] 331 | if diff < lowest 332 | let diff += lookup[ 256 + rgb[0] - r] 333 | if diff < lowest 334 | let diff += lookup[1280 + rgb[2] - b] 335 | if diff < lowest 336 | let lowest = diff 337 | let bestfit = index 338 | endif 339 | if diff <= 0 340 | break 341 | endif 342 | endif 343 | endif 344 | let index += 1 345 | endwhile 346 | return bestfit 347 | endfunc 348 | 349 | 350 | "---------------------------------------------------------------------- 351 | " find match in 8 colors 352 | "---------------------------------------------------------------------- 353 | function! colorexp#palette#bestfit8(r, g, b) 354 | return s:bestfit_color(a:r, a:g, a:b, 8) 355 | endfunc 356 | 357 | 358 | "---------------------------------------------------------------------- 359 | " find match in 8 colors 360 | "---------------------------------------------------------------------- 361 | function! colorexp#palette#bestfit16(r, g, b) 362 | return s:bestfit_color(a:r, a:g, a:b, 16) 363 | endfunc 364 | 365 | 366 | "---------------------------------------------------------------------- 367 | " find match in 8 colors 368 | "---------------------------------------------------------------------- 369 | function! colorexp#palette#bestfit256(r, g, b) 370 | return s:bestfit_color(a:r, a:g, a:b, 256) 371 | endfunc 372 | 373 | 374 | "---------------------------------------------------------------------- 375 | " consider config 376 | "---------------------------------------------------------------------- 377 | function! colorexp#palette#bestfit(r, g, b) 378 | return s:bestfit_color(a:r, a:g, a:b, g:colorexp#palette#number) 379 | endfunc 380 | 381 | 382 | "---------------------------------------------------------------------- 383 | " matched 384 | "---------------------------------------------------------------------- 385 | function! colorexp#palette#match(r, g, b) 386 | let r = (a:r < 256)? (a:r) : 255 387 | let g = (a:g < 256)? (a:g) : 255 388 | let b = (a:b < 256)? (a:b) : 255 389 | let key = (r * 4096 / 4) + (g * 64 / 4) + (b / 4) 390 | if !has_key(s:matched, key) 391 | let n = g:colorexp#palette#number 392 | let s:matched[key] = s:bestfit_color(a:r, a:g, a:b, n) 393 | endif 394 | return s:matched[key] 395 | endfunc 396 | 397 | 398 | "---------------------------------------------------------------------- 399 | " convert #112233 to [0x11, 0x22, 0x33] 400 | "---------------------------------------------------------------------- 401 | function! colorexp#palette#hex2rgb(hex) 402 | let [r, g, b] = [0, 0, 0] 403 | let head = strpart(a:hex, 0, 1) 404 | if head == '#' 405 | let cc = str2nr(strpart(a:hex, 1), 16) 406 | let r = and(cc / 0x10000, 0xff) 407 | let g = and(cc / 0x100, 0xff) 408 | let b = and(cc, 0xff) 409 | elseif head == '(' 410 | let head = strpart(a:hex, 1, len(a:hex) - 2) 411 | let part = split(head, ',') 412 | let r = str2nr(part[0]) 413 | let g = str2nr(part[1]) 414 | let b = str2nr(part[2]) 415 | endif 416 | return [r, g, b] 417 | endfunc 418 | 419 | 420 | "---------------------------------------------------------------------- 421 | " hex to palette index 422 | "---------------------------------------------------------------------- 423 | function! colorexp#palette#hex2index(hex) 424 | let [r, g, b] = colorexp#palette#hex2rgb(a:hex) 425 | return colorexp#palette#match(r, g, b) 426 | endfunc 427 | 428 | 429 | "---------------------------------------------------------------------- 430 | " search name 431 | "---------------------------------------------------------------------- 432 | function! colorexp#palette#name2index(name, ...) 433 | let head = strpart(a:name, 0, 1) 434 | if head == '#' || head == '(' 435 | return colorexp#palette#hex2index(a:name) 436 | else 437 | let default = (a:0 < 1)? 0 : (a:1) 438 | let name = tolower(a:name) 439 | if exists('v:colornames') 440 | if has_key(v:colornames, name) 441 | let hex = v:colornames[name] 442 | return colorexp#palette#hex2index(hex) 443 | endif 444 | endif 445 | return get(s:names, tolower(a:name), default) 446 | endif 447 | endfunc 448 | 449 | 450 | "---------------------------------------------------------------------- 451 | " alpha blend 452 | "---------------------------------------------------------------------- 453 | function! colorexp#palette#blend(c1, c2, alpha) 454 | let c1 = a:c1 455 | let c2 = a:c2 456 | let alpha = a:alpha 457 | if type(c1) == 0 && type(c2) == 0 458 | return (c1 * (255 - alpha) + c2 * alpha) / 255 459 | endif 460 | let dst = colorexp#palette#hex2rgb(c1) 461 | let src = colorexp#palette#hex2rgb(c2) 462 | let r = (dst[0] * (255 - alpha) + src[0] * alpha) / 255 463 | let g = (dst[1] * (255 - alpha) + src[1] * alpha) / 255 464 | let b = (dst[2] * (255 - alpha) + src[2] * alpha) / 255 465 | return printf('#%02x%02x%02x', r, g, b) 466 | endfunc 467 | 468 | 469 | "---------------------------------------------------------------------- 470 | " palette search in desert256 471 | "---------------------------------------------------------------------- 472 | 473 | " returns an approximate grey index for the given grey level 474 | function! s:grey_number(x) 475 | if &t_Co == 88 476 | if a:x < 23 477 | return 0 478 | elseif a:x < 69 479 | return 1 480 | elseif a:x < 103 481 | return 2 482 | elseif a:x < 127 483 | return 3 484 | elseif a:x < 150 485 | return 4 486 | elseif a:x < 173 487 | return 5 488 | elseif a:x < 196 489 | return 6 490 | elseif a:x < 219 491 | return 7 492 | elseif a:x < 243 493 | return 8 494 | else 495 | return 9 496 | endif 497 | else 498 | if a:x < 14 499 | return 0 500 | else 501 | let l:n = (a:x - 8) / 10 502 | let l:m = (a:x - 8) % 10 503 | if l:m < 5 504 | return l:n 505 | else 506 | return l:n + 1 507 | endif 508 | endif 509 | endif 510 | endfunc 511 | 512 | " returns the actual grey level represented by the grey index 513 | function! s:grey_level(n) 514 | if &t_Co == 88 515 | if a:n == 0 516 | return 0 517 | elseif a:n == 1 518 | return 46 519 | elseif a:n == 2 520 | return 92 521 | elseif a:n == 3 522 | return 115 523 | elseif a:n == 4 524 | return 139 525 | elseif a:n == 5 526 | return 162 527 | elseif a:n == 6 528 | return 185 529 | elseif a:n == 7 530 | return 208 531 | elseif a:n == 8 532 | return 231 533 | else 534 | return 255 535 | endif 536 | else 537 | if a:n == 0 538 | return 0 539 | else 540 | return 8 + (a:n * 10) 541 | endif 542 | endif 543 | endfunc 544 | 545 | " returns the palette index for the given grey index 546 | function! s:grey_color(n) 547 | if &t_Co == 88 548 | if a:n == 0 549 | return 16 550 | elseif a:n == 9 551 | return 79 552 | else 553 | return 79 + a:n 554 | endif 555 | else 556 | if a:n == 0 557 | return 16 558 | elseif a:n == 25 559 | return 231 560 | else 561 | return 231 + a:n 562 | endif 563 | endif 564 | endfunc 565 | 566 | " returns an approximate color index for the given color level 567 | function! s:rgb_number(x) 568 | if &t_Co == 88 569 | if a:x < 69 570 | return 0 571 | elseif a:x < 172 572 | return 1 573 | elseif a:x < 230 574 | return 2 575 | else 576 | return 3 577 | endif 578 | else 579 | if a:x < 75 580 | return 0 581 | else 582 | let l:n = (a:x - 55) / 40 583 | let l:m = (a:x - 55) % 40 584 | if l:m < 20 585 | return l:n 586 | else 587 | return l:n + 1 588 | endif 589 | endif 590 | endif 591 | endfunc 592 | 593 | " returns the actual color level for the given color index 594 | function! s:rgb_level(n) 595 | if &t_Co == 88 596 | if a:n == 0 597 | return 0 598 | elseif a:n == 1 599 | return 139 600 | elseif a:n == 2 601 | return 205 602 | else 603 | return 255 604 | endif 605 | else 606 | if a:n == 0 607 | return 0 608 | else 609 | return 55 + (a:n * 40) 610 | endif 611 | endif 612 | endfunc 613 | 614 | " returns the palette index for the given R/G/B color indices 615 | function! s:rgb_color(x, y, z) 616 | if &t_Co == 88 617 | return 16 + (a:x * 16) + (a:y * 4) + a:z 618 | else 619 | return 16 + (a:x * 36) + (a:y * 6) + a:z 620 | endif 621 | endfunc 622 | 623 | " returns the palette index to approximate the given R/G/B color levels 624 | function! colorexp#palette#color_match(r, g, b) 625 | " get the closest grey 626 | let l:gx = s:grey_number(a:r) 627 | let l:gy = s:grey_number(a:g) 628 | let l:gz = s:grey_number(a:b) 629 | 630 | " get the closest color 631 | let l:x = s:rgb_number(a:r) 632 | let l:y = s:rgb_number(a:g) 633 | let l:z = s:rgb_number(a:b) 634 | 635 | if l:gx == l:gy && l:gy == l:gz 636 | " there are two possibilities 637 | let l:dgr = s:grey_level(l:gx) - a:r 638 | let l:dgg = s:grey_level(l:gy) - a:g 639 | let l:dgb = s:grey_level(l:gz) - a:b 640 | let l:dgrey = (l:dgr * l:dgr) + (l:dgg * l:dgg) + (l:dgb * l:dgb) 641 | let l:dr = s:rgb_level(l:gx) - a:r 642 | let l:dg = s:rgb_level(l:gy) - a:g 643 | let l:db = s:rgb_level(l:gz) - a:b 644 | let l:drgb = (l:dr * l:dr) + (l:dg * l:dg) + (l:db * l:db) 645 | if l:dgrey < l:drgb 646 | " use the grey 647 | return s:grey_color(l:gx) 648 | else 649 | " use the color 650 | return s:rgb_color(l:x, l:y, l:z) 651 | endif 652 | else 653 | " only one possibility 654 | return s:rgb_color(l:x, l:y, l:z) 655 | endif 656 | endfun 657 | 658 | function! colorexp#palette#rgb_match(rgb) abort 659 | if a:rgb =~ '^#' 660 | let r = ("0x" . strpart(a:rgb, 1, 2)) + 0 661 | let g = ("0x" . strpart(a:rgb, 3, 2)) + 0 662 | let b = ("0x" . strpart(a:rgb, 5, 2)) + 0 663 | else 664 | let r = ("0x" . strpart(a:rgb, 0, 2)) + 0 665 | let g = ("0x" . strpart(a:rgb, 2, 2)) + 0 666 | let b = ("0x" . strpart(a:rgb, 4, 2)) + 0 667 | endif 668 | return colorexp#palette#color_match(r, g, b) 669 | endfunc 670 | 671 | 672 | "---------------------------------------------------------------------- 673 | " benchmark 674 | "---------------------------------------------------------------------- 675 | function! colorexp#palette#timing() 676 | let ts = reltime() 677 | for i in range(256) 678 | call colorexp#palette#match(i, i, i) 679 | endfor 680 | let tt = reltime(ts) 681 | return reltimestr(tt) 682 | endfunc 683 | 684 | 685 | "---------------------------------------------------------------------- 686 | " optimize if possible: achieve 40x times faster 687 | "---------------------------------------------------------------------- 688 | if has('vim9script') 689 | import './palette9.vim' 690 | function! s:bestfit_color(r, g, b, limit) 691 | return s:palette9.BestfitColor(a:r, a:g, a:b, a:limit) 692 | endfunc 693 | function! colorexp#palette#bestfit8(r, g, b) 694 | return s:palette9.Bestfit8(a:r, a:g, a:b) 695 | endfunc 696 | function! colorexp#palette#bestfit16(r, g, b) 697 | return s:palette9.Bestfit16(a:r, a:g, a:b) 698 | endfunc 699 | function! colorexp#palette#bestfit256(r, g, b) 700 | return s:palette9.Bestfit256(a:r, a:g, a:b) 701 | endfunc 702 | function! colorexp#palette#match(r, g, b) 703 | return s:palette9.Match(a:r, a:g, a:b, g:colorexp#palette#number) 704 | endfunc 705 | function! colorexp#palette#hex2rgb(hex) 706 | return s:palette9.Hex2RGB(a:hex) 707 | endfunc 708 | function! colorexp#palette#hex2index(hex) 709 | return s:palette9.Hex2Index(a:hex) 710 | endfunc 711 | function! colorexp#palette#name2index(name, ...) 712 | let default = (a:0 == 0)? 0 : (a:1) 713 | return s:palette9.Name2Index(a:name, default) 714 | endfunc 715 | endif 716 | 717 | 718 | 719 | 720 | -------------------------------------------------------------------------------- /autoload/colorexp/palette9.vim: -------------------------------------------------------------------------------- 1 | vim9script 2 | 3 | #---------------------------------------------------------------------- 4 | # terminal palette of 256 colors 5 | #---------------------------------------------------------------------- 6 | final color_definition = [ 7 | \ { 'color': 0, 'name': 'Black', 'hex': '#000000' }, 8 | \ { 'color': 1, 'name': 'Maroon', 'hex': '#800000' }, 9 | \ { 'color': 2, 'name': 'Green', 'hex': '#008000' }, 10 | \ { 'color': 3, 'name': 'Olive', 'hex': '#808000' }, 11 | \ { 'color': 4, 'name': 'Navy', 'hex': '#000080' }, 12 | \ { 'color': 5, 'name': 'Purple', 'hex': '#800080' }, 13 | \ { 'color': 6, 'name': 'Teal', 'hex': '#008080' }, 14 | \ { 'color': 7, 'name': 'Silver', 'hex': '#c0c0c0' }, 15 | \ { 'color': 8, 'name': 'Grey', 'hex': '#808080' }, 16 | \ { 'color': 9, 'name': 'Red', 'hex': '#ff0000' }, 17 | \ { 'color': 10, 'name': 'Lime', 'hex': '#00ff00' }, 18 | \ { 'color': 11, 'name': 'Yellow', 'hex': '#ffff00' }, 19 | \ { 'color': 12, 'name': 'Blue', 'hex': '#0000ff' }, 20 | \ { 'color': 13, 'name': 'Fuchsia', 'hex': '#ff00ff' }, 21 | \ { 'color': 14, 'name': 'Aqua', 'hex': '#00ffff' }, 22 | \ { 'color': 15, 'name': 'White', 'hex': '#ffffff' }, 23 | \ { 'color': 16, 'name': 'Grey0', 'hex': '#000000' }, 24 | \ { 'color': 17, 'name': 'NavyBlue', 'hex': '#00005f' }, 25 | \ { 'color': 18, 'name': 'DarkBlue', 'hex': '#000087' }, 26 | \ { 'color': 19, 'name': 'Blue3', 'hex': '#0000af' }, 27 | \ { 'color': 20, 'name': 'Blue3', 'hex': '#0000d7' }, 28 | \ { 'color': 21, 'name': 'Blue1', 'hex': '#0000ff' }, 29 | \ { 'color': 22, 'name': 'DarkGreen', 'hex': '#005f00' }, 30 | \ { 'color': 23, 'name': 'DeepSkyBlue4', 'hex': '#005f5f' }, 31 | \ { 'color': 24, 'name': 'DeepSkyBlue4', 'hex': '#005f87' }, 32 | \ { 'color': 25, 'name': 'DeepSkyBlue4', 'hex': '#005faf' }, 33 | \ { 'color': 26, 'name': 'DodgerBlue3', 'hex': '#005fd7' }, 34 | \ { 'color': 27, 'name': 'DodgerBlue2', 'hex': '#005fff' }, 35 | \ { 'color': 28, 'name': 'Green4', 'hex': '#008700' }, 36 | \ { 'color': 29, 'name': 'SpringGreen4', 'hex': '#00875f' }, 37 | \ { 'color': 30, 'name': 'Turquoise4', 'hex': '#008787' }, 38 | \ { 'color': 31, 'name': 'DeepSkyBlue3', 'hex': '#0087af' }, 39 | \ { 'color': 32, 'name': 'DeepSkyBlue3', 'hex': '#0087d7' }, 40 | \ { 'color': 33, 'name': 'DodgerBlue1', 'hex': '#0087ff' }, 41 | \ { 'color': 34, 'name': 'Green3', 'hex': '#00af00' }, 42 | \ { 'color': 35, 'name': 'SpringGreen3', 'hex': '#00af5f' }, 43 | \ { 'color': 36, 'name': 'DarkCyan', 'hex': '#00af87' }, 44 | \ { 'color': 37, 'name': 'LightSeaGreen', 'hex': '#00afaf' }, 45 | \ { 'color': 38, 'name': 'DeepSkyBlue2', 'hex': '#00afd7' }, 46 | \ { 'color': 39, 'name': 'DeepSkyBlue1', 'hex': '#00afff' }, 47 | \ { 'color': 40, 'name': 'Green3', 'hex': '#00d700' }, 48 | \ { 'color': 41, 'name': 'SpringGreen3', 'hex': '#00d75f' }, 49 | \ { 'color': 42, 'name': 'SpringGreen2', 'hex': '#00d787' }, 50 | \ { 'color': 43, 'name': 'Cyan3', 'hex': '#00d7af' }, 51 | \ { 'color': 44, 'name': 'DarkTurquoise', 'hex': '#00d7d7' }, 52 | \ { 'color': 45, 'name': 'Turquoise2', 'hex': '#00d7ff' }, 53 | \ { 'color': 46, 'name': 'Green1', 'hex': '#00ff00' }, 54 | \ { 'color': 47, 'name': 'SpringGreen2', 'hex': '#00ff5f' }, 55 | \ { 'color': 48, 'name': 'SpringGreen1', 'hex': '#00ff87' }, 56 | \ { 'color': 49, 'name': 'MediumSpringGreen', 'hex': '#00ffaf' }, 57 | \ { 'color': 50, 'name': 'Cyan2', 'hex': '#00ffd7' }, 58 | \ { 'color': 51, 'name': 'Cyan1', 'hex': '#00ffff' }, 59 | \ { 'color': 52, 'name': 'DarkRed', 'hex': '#5f0000' }, 60 | \ { 'color': 53, 'name': 'DeepPink4', 'hex': '#5f005f' }, 61 | \ { 'color': 54, 'name': 'Purple4', 'hex': '#5f0087' }, 62 | \ { 'color': 55, 'name': 'Purple4', 'hex': '#5f00af' }, 63 | \ { 'color': 56, 'name': 'Purple3', 'hex': '#5f00d7' }, 64 | \ { 'color': 57, 'name': 'BlueViolet', 'hex': '#5f00ff' }, 65 | \ { 'color': 58, 'name': 'Orange4', 'hex': '#5f5f00' }, 66 | \ { 'color': 59, 'name': 'Grey37', 'hex': '#5f5f5f' }, 67 | \ { 'color': 60, 'name': 'MediumPurple4', 'hex': '#5f5f87' }, 68 | \ { 'color': 61, 'name': 'SlateBlue3', 'hex': '#5f5faf' }, 69 | \ { 'color': 62, 'name': 'SlateBlue3', 'hex': '#5f5fd7' }, 70 | \ { 'color': 63, 'name': 'RoyalBlue1', 'hex': '#5f5fff' }, 71 | \ { 'color': 64, 'name': 'Chartreuse4', 'hex': '#5f8700' }, 72 | \ { 'color': 65, 'name': 'DarkSeaGreen4', 'hex': '#5f875f' }, 73 | \ { 'color': 66, 'name': 'PaleTurquoise4', 'hex': '#5f8787' }, 74 | \ { 'color': 67, 'name': 'SteelBlue', 'hex': '#5f87af' }, 75 | \ { 'color': 68, 'name': 'SteelBlue3', 'hex': '#5f87d7' }, 76 | \ { 'color': 69, 'name': 'CornflowerBlue', 'hex': '#5f87ff' }, 77 | \ { 'color': 70, 'name': 'Chartreuse3', 'hex': '#5faf00' }, 78 | \ { 'color': 71, 'name': 'DarkSeaGreen4', 'hex': '#5faf5f' }, 79 | \ { 'color': 72, 'name': 'CadetBlue', 'hex': '#5faf87' }, 80 | \ { 'color': 73, 'name': 'CadetBlue', 'hex': '#5fafaf' }, 81 | \ { 'color': 74, 'name': 'SkyBlue3', 'hex': '#5fafd7' }, 82 | \ { 'color': 75, 'name': 'SteelBlue1', 'hex': '#5fafff' }, 83 | \ { 'color': 76, 'name': 'Chartreuse3', 'hex': '#5fd700' }, 84 | \ { 'color': 77, 'name': 'PaleGreen3', 'hex': '#5fd75f' }, 85 | \ { 'color': 78, 'name': 'SeaGreen3', 'hex': '#5fd787' }, 86 | \ { 'color': 79, 'name': 'Aquamarine3', 'hex': '#5fd7af' }, 87 | \ { 'color': 80, 'name': 'MediumTurquoise', 'hex': '#5fd7d7' }, 88 | \ { 'color': 81, 'name': 'SteelBlue1', 'hex': '#5fd7ff' }, 89 | \ { 'color': 82, 'name': 'Chartreuse2', 'hex': '#5fff00' }, 90 | \ { 'color': 83, 'name': 'SeaGreen2', 'hex': '#5fff5f' }, 91 | \ { 'color': 84, 'name': 'SeaGreen1', 'hex': '#5fff87' }, 92 | \ { 'color': 85, 'name': 'SeaGreen1', 'hex': '#5fffaf' }, 93 | \ { 'color': 86, 'name': 'Aquamarine1', 'hex': '#5fffd7' }, 94 | \ { 'color': 87, 'name': 'DarkSlateGray2', 'hex': '#5fffff' }, 95 | \ { 'color': 88, 'name': 'DarkRed', 'hex': '#870000' }, 96 | \ { 'color': 89, 'name': 'DeepPink4', 'hex': '#87005f' }, 97 | \ { 'color': 90, 'name': 'DarkMagenta', 'hex': '#870087' }, 98 | \ { 'color': 91, 'name': 'DarkMagenta', 'hex': '#8700af' }, 99 | \ { 'color': 92, 'name': 'DarkViolet', 'hex': '#8700d7' }, 100 | \ { 'color': 93, 'name': 'Purple', 'hex': '#8700ff' }, 101 | \ { 'color': 94, 'name': 'Orange4', 'hex': '#875f00' }, 102 | \ { 'color': 95, 'name': 'LightPink4', 'hex': '#875f5f' }, 103 | \ { 'color': 96, 'name': 'Plum4', 'hex': '#875f87' }, 104 | \ { 'color': 97, 'name': 'MediumPurple3', 'hex': '#875faf' }, 105 | \ { 'color': 98, 'name': 'MediumPurple3', 'hex': '#875fd7' }, 106 | \ { 'color': 99, 'name': 'SlateBlue1', 'hex': '#875fff' }, 107 | \ { 'color': 100, 'name': 'Yellow4', 'hex': '#878700' }, 108 | \ { 'color': 101, 'name': 'Wheat4', 'hex': '#87875f' }, 109 | \ { 'color': 102, 'name': 'Grey53', 'hex': '#878787' }, 110 | \ { 'color': 103, 'name': 'LightSlateGrey', 'hex': '#8787af' }, 111 | \ { 'color': 104, 'name': 'MediumPurple', 'hex': '#8787d7' }, 112 | \ { 'color': 105, 'name': 'LightSlateBlue', 'hex': '#8787ff' }, 113 | \ { 'color': 106, 'name': 'Yellow4', 'hex': '#87af00' }, 114 | \ { 'color': 107, 'name': 'DarkOliveGreen3', 'hex': '#87af5f' }, 115 | \ { 'color': 108, 'name': 'DarkSeaGreen', 'hex': '#87af87' }, 116 | \ { 'color': 109, 'name': 'LightSkyBlue3', 'hex': '#87afaf' }, 117 | \ { 'color': 110, 'name': 'LightSkyBlue3', 'hex': '#87afd7' }, 118 | \ { 'color': 111, 'name': 'SkyBlue2', 'hex': '#87afff' }, 119 | \ { 'color': 112, 'name': 'Chartreuse2', 'hex': '#87d700' }, 120 | \ { 'color': 113, 'name': 'DarkOliveGreen3', 'hex': '#87d75f' }, 121 | \ { 'color': 114, 'name': 'PaleGreen3', 'hex': '#87d787' }, 122 | \ { 'color': 115, 'name': 'DarkSeaGreen3', 'hex': '#87d7af' }, 123 | \ { 'color': 116, 'name': 'DarkSlateGray3', 'hex': '#87d7d7' }, 124 | \ { 'color': 117, 'name': 'SkyBlue1', 'hex': '#87d7ff' }, 125 | \ { 'color': 118, 'name': 'Chartreuse1', 'hex': '#87ff00' }, 126 | \ { 'color': 119, 'name': 'LightGreen', 'hex': '#87ff5f' }, 127 | \ { 'color': 120, 'name': 'LightGreen', 'hex': '#87ff87' }, 128 | \ { 'color': 121, 'name': 'PaleGreen1', 'hex': '#87ffaf' }, 129 | \ { 'color': 122, 'name': 'Aquamarine1', 'hex': '#87ffd7' }, 130 | \ { 'color': 123, 'name': 'DarkSlateGray1', 'hex': '#87ffff' }, 131 | \ { 'color': 124, 'name': 'Red3', 'hex': '#af0000' }, 132 | \ { 'color': 125, 'name': 'DeepPink4', 'hex': '#af005f' }, 133 | \ { 'color': 126, 'name': 'MediumVioletRed', 'hex': '#af0087' }, 134 | \ { 'color': 127, 'name': 'Magenta3', 'hex': '#af00af' }, 135 | \ { 'color': 128, 'name': 'DarkViolet', 'hex': '#af00d7' }, 136 | \ { 'color': 129, 'name': 'Purple', 'hex': '#af00ff' }, 137 | \ { 'color': 130, 'name': 'DarkOrange3', 'hex': '#af5f00' }, 138 | \ { 'color': 131, 'name': 'IndianRed', 'hex': '#af5f5f' }, 139 | \ { 'color': 132, 'name': 'HotPink3', 'hex': '#af5f87' }, 140 | \ { 'color': 133, 'name': 'MediumOrchid3', 'hex': '#af5faf' }, 141 | \ { 'color': 134, 'name': 'MediumOrchid', 'hex': '#af5fd7' }, 142 | \ { 'color': 135, 'name': 'MediumPurple2', 'hex': '#af5fff' }, 143 | \ { 'color': 136, 'name': 'DarkGoldenrod', 'hex': '#af8700' }, 144 | \ { 'color': 137, 'name': 'LightSalmon3', 'hex': '#af875f' }, 145 | \ { 'color': 138, 'name': 'RosyBrown', 'hex': '#af8787' }, 146 | \ { 'color': 139, 'name': 'Grey63', 'hex': '#af87af' }, 147 | \ { 'color': 140, 'name': 'MediumPurple2', 'hex': '#af87d7' }, 148 | \ { 'color': 141, 'name': 'MediumPurple1', 'hex': '#af87ff' }, 149 | \ { 'color': 142, 'name': 'Gold3', 'hex': '#afaf00' }, 150 | \ { 'color': 143, 'name': 'DarkKhaki', 'hex': '#afaf5f' }, 151 | \ { 'color': 144, 'name': 'NavajoWhite3', 'hex': '#afaf87' }, 152 | \ { 'color': 145, 'name': 'Grey69', 'hex': '#afafaf' }, 153 | \ { 'color': 146, 'name': 'LightSteelBlue3', 'hex': '#afafd7' }, 154 | \ { 'color': 147, 'name': 'LightSteelBlue', 'hex': '#afafff' }, 155 | \ { 'color': 148, 'name': 'Yellow3', 'hex': '#afd700' }, 156 | \ { 'color': 149, 'name': 'DarkOliveGreen3', 'hex': '#afd75f' }, 157 | \ { 'color': 150, 'name': 'DarkSeaGreen3', 'hex': '#afd787' }, 158 | \ { 'color': 151, 'name': 'DarkSeaGreen2', 'hex': '#afd7af' }, 159 | \ { 'color': 152, 'name': 'LightCyan3', 'hex': '#afd7d7' }, 160 | \ { 'color': 153, 'name': 'LightSkyBlue1', 'hex': '#afd7ff' }, 161 | \ { 'color': 154, 'name': 'GreenYellow', 'hex': '#afff00' }, 162 | \ { 'color': 155, 'name': 'DarkOliveGreen2', 'hex': '#afff5f' }, 163 | \ { 'color': 156, 'name': 'PaleGreen1', 'hex': '#afff87' }, 164 | \ { 'color': 157, 'name': 'DarkSeaGreen2', 'hex': '#afffaf' }, 165 | \ { 'color': 158, 'name': 'DarkSeaGreen1', 'hex': '#afffd7' }, 166 | \ { 'color': 159, 'name': 'PaleTurquoise1', 'hex': '#afffff' }, 167 | \ { 'color': 160, 'name': 'Red3', 'hex': '#d70000' }, 168 | \ { 'color': 161, 'name': 'DeepPink3', 'hex': '#d7005f' }, 169 | \ { 'color': 162, 'name': 'DeepPink3', 'hex': '#d70087' }, 170 | \ { 'color': 163, 'name': 'Magenta3', 'hex': '#d700af' }, 171 | \ { 'color': 164, 'name': 'Magenta3', 'hex': '#d700d7' }, 172 | \ { 'color': 165, 'name': 'Magenta2', 'hex': '#d700ff' }, 173 | \ { 'color': 166, 'name': 'DarkOrange3', 'hex': '#d75f00' }, 174 | \ { 'color': 167, 'name': 'IndianRed', 'hex': '#d75f5f' }, 175 | \ { 'color': 168, 'name': 'HotPink3', 'hex': '#d75f87' }, 176 | \ { 'color': 169, 'name': 'HotPink2', 'hex': '#d75faf' }, 177 | \ { 'color': 170, 'name': 'Orchid', 'hex': '#d75fd7' }, 178 | \ { 'color': 171, 'name': 'MediumOrchid1', 'hex': '#d75fff' }, 179 | \ { 'color': 172, 'name': 'Orange3', 'hex': '#d78700' }, 180 | \ { 'color': 173, 'name': 'LightSalmon3', 'hex': '#d7875f' }, 181 | \ { 'color': 174, 'name': 'LightPink3', 'hex': '#d78787' }, 182 | \ { 'color': 175, 'name': 'Pink3', 'hex': '#d787af' }, 183 | \ { 'color': 176, 'name': 'Plum3', 'hex': '#d787d7' }, 184 | \ { 'color': 177, 'name': 'Violet', 'hex': '#d787ff' }, 185 | \ { 'color': 178, 'name': 'Gold3', 'hex': '#d7af00' }, 186 | \ { 'color': 179, 'name': 'LightGoldenrod3', 'hex': '#d7af5f' }, 187 | \ { 'color': 180, 'name': 'Tan', 'hex': '#d7af87' }, 188 | \ { 'color': 181, 'name': 'MistyRose3', 'hex': '#d7afaf' }, 189 | \ { 'color': 182, 'name': 'Thistle3', 'hex': '#d7afd7' }, 190 | \ { 'color': 183, 'name': 'Plum2', 'hex': '#d7afff' }, 191 | \ { 'color': 184, 'name': 'Yellow3', 'hex': '#d7d700' }, 192 | \ { 'color': 185, 'name': 'Khaki3', 'hex': '#d7d75f' }, 193 | \ { 'color': 186, 'name': 'LightGoldenrod2', 'hex': '#d7d787' }, 194 | \ { 'color': 187, 'name': 'LightYellow3', 'hex': '#d7d7af' }, 195 | \ { 'color': 188, 'name': 'Grey84', 'hex': '#d7d7d7' }, 196 | \ { 'color': 189, 'name': 'LightSteelBlue1', 'hex': '#d7d7ff' }, 197 | \ { 'color': 190, 'name': 'Yellow2', 'hex': '#d7ff00' }, 198 | \ { 'color': 191, 'name': 'DarkOliveGreen1', 'hex': '#d7ff5f' }, 199 | \ { 'color': 192, 'name': 'DarkOliveGreen1', 'hex': '#d7ff87' }, 200 | \ { 'color': 193, 'name': 'DarkSeaGreen1', 'hex': '#d7ffaf' }, 201 | \ { 'color': 194, 'name': 'Honeydew2', 'hex': '#d7ffd7' }, 202 | \ { 'color': 195, 'name': 'LightCyan1', 'hex': '#d7ffff' }, 203 | \ { 'color': 196, 'name': 'Red1', 'hex': '#ff0000' }, 204 | \ { 'color': 197, 'name': 'DeepPink2', 'hex': '#ff005f' }, 205 | \ { 'color': 198, 'name': 'DeepPink1', 'hex': '#ff0087' }, 206 | \ { 'color': 199, 'name': 'DeepPink1', 'hex': '#ff00af' }, 207 | \ { 'color': 200, 'name': 'Magenta2', 'hex': '#ff00d7' }, 208 | \ { 'color': 201, 'name': 'Magenta1', 'hex': '#ff00ff' }, 209 | \ { 'color': 202, 'name': 'OrangeRed1', 'hex': '#ff5f00' }, 210 | \ { 'color': 203, 'name': 'IndianRed1', 'hex': '#ff5f5f' }, 211 | \ { 'color': 204, 'name': 'IndianRed1', 'hex': '#ff5f87' }, 212 | \ { 'color': 205, 'name': 'HotPink', 'hex': '#ff5faf' }, 213 | \ { 'color': 206, 'name': 'HotPink', 'hex': '#ff5fd7' }, 214 | \ { 'color': 207, 'name': 'MediumOrchid1', 'hex': '#ff5fff' }, 215 | \ { 'color': 208, 'name': 'DarkOrange', 'hex': '#ff8700' }, 216 | \ { 'color': 209, 'name': 'Salmon1', 'hex': '#ff875f' }, 217 | \ { 'color': 210, 'name': 'LightCoral', 'hex': '#ff8787' }, 218 | \ { 'color': 211, 'name': 'PaleVioletRed1', 'hex': '#ff87af' }, 219 | \ { 'color': 212, 'name': 'Orchid2', 'hex': '#ff87d7' }, 220 | \ { 'color': 213, 'name': 'Orchid1', 'hex': '#ff87ff' }, 221 | \ { 'color': 214, 'name': 'Orange1', 'hex': '#ffaf00' }, 222 | \ { 'color': 215, 'name': 'SandyBrown', 'hex': '#ffaf5f' }, 223 | \ { 'color': 216, 'name': 'LightSalmon1', 'hex': '#ffaf87' }, 224 | \ { 'color': 217, 'name': 'LightPink1', 'hex': '#ffafaf' }, 225 | \ { 'color': 218, 'name': 'Pink1', 'hex': '#ffafd7' }, 226 | \ { 'color': 219, 'name': 'Plum1', 'hex': '#ffafff' }, 227 | \ { 'color': 220, 'name': 'Gold1', 'hex': '#ffd700' }, 228 | \ { 'color': 221, 'name': 'LightGoldenrod2', 'hex': '#ffd75f' }, 229 | \ { 'color': 222, 'name': 'LightGoldenrod2', 'hex': '#ffd787' }, 230 | \ { 'color': 223, 'name': 'NavajoWhite1', 'hex': '#ffd7af' }, 231 | \ { 'color': 224, 'name': 'MistyRose1', 'hex': '#ffd7d7' }, 232 | \ { 'color': 225, 'name': 'Thistle1', 'hex': '#ffd7ff' }, 233 | \ { 'color': 226, 'name': 'Yellow1', 'hex': '#ffff00' }, 234 | \ { 'color': 227, 'name': 'LightGoldenrod1', 'hex': '#ffff5f' }, 235 | \ { 'color': 228, 'name': 'Khaki1', 'hex': '#ffff87' }, 236 | \ { 'color': 229, 'name': 'Wheat1', 'hex': '#ffffaf' }, 237 | \ { 'color': 230, 'name': 'Cornsilk1', 'hex': '#ffffd7' }, 238 | \ { 'color': 231, 'name': 'Grey100', 'hex': '#ffffff' }, 239 | \ { 'color': 232, 'name': 'Grey3', 'hex': '#080808' }, 240 | \ { 'color': 233, 'name': 'Grey7', 'hex': '#121212' }, 241 | \ { 'color': 234, 'name': 'Grey11', 'hex': '#1c1c1c' }, 242 | \ { 'color': 235, 'name': 'Grey15', 'hex': '#262626' }, 243 | \ { 'color': 236, 'name': 'Grey19', 'hex': '#303030' }, 244 | \ { 'color': 237, 'name': 'Grey23', 'hex': '#3a3a3a' }, 245 | \ { 'color': 238, 'name': 'Grey27', 'hex': '#444444' }, 246 | \ { 'color': 239, 'name': 'Grey30', 'hex': '#4e4e4e' }, 247 | \ { 'color': 240, 'name': 'Grey35', 'hex': '#585858' }, 248 | \ { 'color': 241, 'name': 'Grey39', 'hex': '#626262' }, 249 | \ { 'color': 242, 'name': 'Grey42', 'hex': '#6c6c6c' }, 250 | \ { 'color': 243, 'name': 'Grey46', 'hex': '#767676' }, 251 | \ { 'color': 244, 'name': 'Grey50', 'hex': '#808080' }, 252 | \ { 'color': 245, 'name': 'Grey54', 'hex': '#8a8a8a' }, 253 | \ { 'color': 246, 'name': 'Grey58', 'hex': '#949494' }, 254 | \ { 'color': 247, 'name': 'Grey62', 'hex': '#9e9e9e' }, 255 | \ { 'color': 248, 'name': 'Grey66', 'hex': '#a8a8a8' }, 256 | \ { 'color': 249, 'name': 'Grey70', 'hex': '#b2b2b2' }, 257 | \ { 'color': 250, 'name': 'Grey74', 'hex': '#bcbcbc' }, 258 | \ { 'color': 251, 'name': 'Grey78', 'hex': '#c6c6c6' }, 259 | \ { 'color': 252, 'name': 'Grey82', 'hex': '#d0d0d0' }, 260 | \ { 'color': 253, 'name': 'Grey85', 'hex': '#dadada' }, 261 | \ { 'color': 254, 'name': 'Grey89', 'hex': '#e4e4e4' }, 262 | \ { 'color': 255, 'name': 'Grey93', 'hex': '#eeeeee' }, 263 | \ ] 264 | 265 | 266 | #---------------------------------------------------------------------- 267 | # initialize 268 | #---------------------------------------------------------------------- 269 | var _palette: list> 270 | var cnames = {} 271 | 272 | for color in color_definition 273 | final cc: number = str2nr(strpart(color.hex, 1), 16) 274 | final r: number = and(cc / 0x10000, 0xff) 275 | final g: number = and(cc / 0x100, 0xff) 276 | final b: number = and(cc, 0xff) 277 | final p: list = [r, g, b] 278 | _palette += [p] 279 | cnames[tolower(color.name)] = color.color 280 | endfor 281 | 282 | final palette: list> = deepcopy(_palette) 283 | var _diff_lookup: list = repeat([0], 512 * 3) 284 | 285 | for i in range(256) 286 | final k: number = i * i 287 | final dr: number = k * 30 * 30 288 | final dg: number = k * 59 * 59 289 | final db: number = k * 11 * 11 290 | _diff_lookup[ 256 + i] = dr 291 | _diff_lookup[ 256 - i] = dr 292 | _diff_lookup[ 768 + i] = dg 293 | _diff_lookup[ 768 - i] = dg 294 | _diff_lookup[1280 + i] = db 295 | _diff_lookup[1280 - i] = db 296 | endfor 297 | 298 | final diff_lookup: list = deepcopy(_diff_lookup) 299 | 300 | 301 | #---------------------------------------------------------------------- 302 | # bestfit color 303 | #---------------------------------------------------------------------- 304 | export def BestfitColor(r: number, g: number, b: number, limit: number = 256): number 305 | final R: number = (r < 256) ? r : 255 306 | final G: number = (g < 256) ? g : 255 307 | final B: number = (b < 256) ? b : 255 308 | final LIMIT: number = (limit < 256) ? limit : 256 309 | final lookup: list = diff_lookup 310 | var lowest = 0x7fffffff 311 | var bestfit = 0 312 | var index = 0 313 | while index < LIMIT 314 | final rgb: list = palette[index] 315 | var diff = lookup[768 + rgb[1] - G] 316 | if diff < lowest 317 | diff += lookup[256 + rgb[0] - R] 318 | if diff < lowest 319 | diff += lookup[1280 + rgb[2] - B] 320 | if diff < lowest 321 | lowest = diff 322 | bestfit = index 323 | endif 324 | if diff <= 0 325 | break 326 | endif 327 | endif 328 | endif 329 | index += 1 330 | endwhile 331 | return bestfit 332 | enddef 333 | 334 | 335 | #---------------------------------------------------------------------- 336 | # for 8 colors 337 | #---------------------------------------------------------------------- 338 | export def Bestfit8(r: number, g: number, b: number): number 339 | return BestfitColor(r, g, b, 8) 340 | enddef 341 | 342 | 343 | #---------------------------------------------------------------------- 344 | # for 16 colors 345 | #---------------------------------------------------------------------- 346 | export def Bestfit16(r: number, g: number, b: number): number 347 | return BestfitColor(r, g, b, 16) 348 | enddef 349 | 350 | #---------------------------------------------------------------------- 351 | # for 256 colors 352 | #---------------------------------------------------------------------- 353 | export def Bestfit256(r: number, g: number, b: number): number 354 | return BestfitColor(r, g, b, 256) 355 | enddef 356 | 357 | 358 | #---------------------------------------------------------------------- 359 | # for 256 colors 360 | #---------------------------------------------------------------------- 361 | var matched = {} 362 | 363 | export def Match(r: number, g: number, b: number, num: number = -1): number 364 | final rr = (r < 256) ? r : 255 365 | final gg = (g < 256) ? g : 255 366 | final bb = (b < 256) ? b : 255 367 | final key: number = (rr * 4096 / 4) + (gg * 64 / 4) + (bb / 4) 368 | if !has_key(matched, key) 369 | var N: number = 256 370 | if num >= 0 371 | N = num 372 | else 373 | if exists('g:colorexp#palette#number') 374 | N = g:colorexp#palette#number 375 | endif 376 | endif 377 | final cc: number = BestfitColor(rr, gg, bb, N) 378 | matched[key] = cc 379 | endif 380 | return matched[key] 381 | enddef 382 | 383 | 384 | #---------------------------------------------------------------------- 385 | # convert #112233 to [0x11, 0x22, 0x33] 386 | #---------------------------------------------------------------------- 387 | export def Hex2RGB(hex: string): list 388 | var head: string = strpart(hex, 0, 1) 389 | var r: number = 0 390 | var g: number = 0 391 | var b: number = 0 392 | if head == '#' 393 | final c: number = str2nr(strpart(hex, 1), 16) 394 | r = and(c / 0x10000, 0xff) 395 | g = and(c / 0x100, 0xff) 396 | b = and(c, 0xff) 397 | elseif head == '(' 398 | head = strpart(hex, 1, len(hex) - 2) 399 | final part: list = split(head, ',') 400 | r = str2nr(part[0]) 401 | g = str2nr(part[1]) 402 | b = str2nr(part[2]) 403 | endif 404 | return [r, g, b] 405 | enddef 406 | 407 | 408 | #---------------------------------------------------------------------- 409 | # hex to palette index 410 | #---------------------------------------------------------------------- 411 | export def Hex2Index(hex: string, num: number = -1): number 412 | final cc: list = Hex2RGB(hex) 413 | return Match(cc[0], cc[1], cc[2], num) 414 | enddef 415 | 416 | 417 | #---------------------------------------------------------------------- 418 | # search name 419 | #---------------------------------------------------------------------- 420 | export def Name2Index(name: string, default: number = 0): number 421 | final head = strpart(name, 0, 1) 422 | if head == '#' || head == '(' 423 | return Hex2Index(name) 424 | else 425 | final nm = tolower(name) 426 | if exists('v:colornames') 427 | if has_key(v:colornames, nm) 428 | final hex = v:colornames[nm] 429 | return Hex2Index(hex) 430 | endif 431 | endif 432 | return get(cnames, tolower(name), default) 433 | endif 434 | enddef 435 | 436 | 437 | #---------------------------------------------------------------------- 438 | # benchmark 439 | #---------------------------------------------------------------------- 440 | export def Timing(): string 441 | var ts = reltime() 442 | for i in range(256) 443 | Match(i, i, i) 444 | endfor 445 | var tt = reltime(ts) 446 | return reltimestr(tt) 447 | enddef 448 | 449 | 450 | -------------------------------------------------------------------------------- /plugin/colorexp.vim: -------------------------------------------------------------------------------- 1 | "====================================================================== 2 | " 3 | " colorexp.vim - 4 | " 5 | " Created by skywind on 2024/02/01 6 | " Last Modified: 2024/02/01 16:37:38 7 | " 8 | "====================================================================== 9 | 10 | 11 | "---------------------------------------------------------------------- 12 | " error message 13 | "---------------------------------------------------------------------- 14 | function! s:errmsg(text) 15 | echohl ErrorMsg 16 | echom a:text 17 | echohl None 18 | endfunc 19 | 20 | 21 | "---------------------------------------------------------------------- 22 | " strip text 23 | "---------------------------------------------------------------------- 24 | function! s:StringStrip(text) 25 | return substitute(a:text, '^\s*\(.\{-}\)\s*$', '\1', '') 26 | endfunc 27 | 28 | 29 | "---------------------------------------------------------------------- 30 | " command 31 | "---------------------------------------------------------------------- 32 | command! -bang -nargs=1 -range=0 -complete=file ColorExport 33 | \ call s:ColorExport(0, ) 34 | 35 | function! s:ColorExport(bang, name) 36 | let name = expand(a:name) 37 | if name !~ '\.vim$' 38 | let name = name .. '.vim' 39 | endif 40 | if filereadable(name) 41 | if a:bang == 0 42 | call s:errmsg('File already exists, use :ColorExport! to overwrite') 43 | return 0 44 | endif 45 | endif 46 | let dirhome = fnamemodify(name, ':p:h') 47 | if !isdirectory(dirhome) 48 | call s:errmsg(printf('Directory does not exist: %s', dirhome)) 49 | return 0 50 | endif 51 | let ts = reltime() 52 | call colorexp#export#proceed(name) 53 | let tt = reltime(ts) 54 | let time = reltimestr(tt) 55 | let time = s:StringStrip(time) 56 | echo printf('"%s" exported in %s seconds', name, time) 57 | return 1 58 | endfunc 59 | 60 | 61 | --------------------------------------------------------------------------------