Defining a color variable in vim

When, for example, when creating a color scheme, how to define # 40ffff as "UglyColor" (ie as a variable)?

Possible / Impossible?

+4
source share
1 answer

This is not possible with the built-in syntax. However, this can be done if you created your own syntax:

let UglyColor = '#40ffff' let Greenish = '#00dd00' let MyStyle = 'bold' exe 'hi Keyword gui=' . MyStyle . ' guifg=' . UglyColor exe 'hi Comment guifg=' . Greenish 

You can then do this by creating a dictionary:

 let UglyColor = '#40ffff' let Greenish = '#00dd00' let ColourAssignment = {} let ColourAssignment['Keyword'] = {"GUIFG": UglyColor, "GUI": "Bold"} let ColourAssignment['Comment'] = {"GUIFG": Greenish} 

And then process it like this:

 for key in keys(ColourAssignment) let s:colours = ColourAssignment[key] if has_key(s:colours, 'GUI') let gui = s:colours['GUI'] else let gui='NONE' endif if has_key(s:colours, 'GUIFG') let guifg = s:colours['GUIFG'] else let guifg='NONE' endif if has_key(s:colours, 'GUIBG') let guibg = s:colours['GUIBG'] else let guibg='NONE' endif if key =~ '^\k*$' execute "hi ".key." term=".term." cterm=".cterm." gui=".gui." ctermfg=".ctermfg." guifg=".guifg." ctermbg=".ctermbg." guibg=".guibg." guisp=".guisp endif 

This is how my Bandit color scheme works (with a little more logical there for automatically generating cterm colors, background colors and syntax file so that the color scheme is self-esteem). Feel free to take a look at this and steal the features and format your own color scheme.

+5
source

Source: https://habr.com/ru/post/1304099/


All Articles