mirror of
https://github.com/joshdick/onedark.vim.git
synced 2025-11-08 11:03:49 -05:00
Enhance the implementation of onedark#extend_highlight and improve the README
This commit is contained in:
33
README.md
33
README.md
@@ -158,21 +158,29 @@ onedark.vim exposes `onedark#extend_highlight` and `onedark#set_highlight` funct
|
||||
|
||||
`onedark#extend_highlight` allows you to customize individual aspects of onedark.vim's existing highlight groups, overriding only the keys you provide. (To completely redefine/override an existing highlight group, see `onedark#set_highlight` below.)
|
||||
|
||||
`onedark#extend_highlight`'s first argunment should be the name of a highlight group, and its second argument should be style data.
|
||||
`onedark#extend_highlight`'s first argunment should be the name of a highlight group, and its second argument should be **partial** style data.
|
||||
|
||||
For example, if you want functions to be bold only in GUI mode, place the following lines **before** the `colorscheme onedark` line in your `~/.vimrc`:
|
||||
Place the following lines **before** the `colorscheme onedark` line in your `~/.vimrc`, then change the example overrides to suit your needs:
|
||||
|
||||
```vim
|
||||
if (has("autocmd") && has("gui_running"))
|
||||
autocmd ColorScheme * call onedark#extend_highlight("Function", { "gui": "bold" })
|
||||
end
|
||||
if (has("autocmd"))
|
||||
augroup colorextend
|
||||
autocmd!
|
||||
" Make `Function`s bold in GUI mode
|
||||
autocmd ColorScheme * call onedark#extend_highlight("Function", { "gui": "bold" })
|
||||
" Override the `Statement` foreground color in 256-color mode
|
||||
autocmd ColorScheme * call onedark#extend_highlight("Statement", { "fg": { "cterm": 128 } })
|
||||
" Override the `Identifier` background color in GUI mode
|
||||
autocmd ColorScheme * call onedark#extend_highlight("Identifier", { "bg": { "gui": "#333333" } })
|
||||
augroup END
|
||||
endif
|
||||
```
|
||||
|
||||
#### `onedark#set_highlight`
|
||||
|
||||
`onedark#set_highlight` allows you to completely redefine/override highlight groups of your choosing.
|
||||
|
||||
`onedark#set_highlight`'s first argument should be the name of a highlight group, and its second argument should be style data.
|
||||
`onedark#set_highlight`'s first argument should be the name of a highlight group, and its second argument should be **complete** style data.
|
||||
|
||||
For example, to remove the background color only when running in terminals (outside GUI mode and for use in transparent terminals,) place the following lines **before** the `colorscheme onedark` line in your `~/.vimrc`:
|
||||
|
||||
@@ -183,12 +191,17 @@ For example, to remove the background color only when running in terminals (outs
|
||||
" `cterm` is the color code used in 256-color mode
|
||||
" `cterm16` is the color code used in 16-color mode
|
||||
if (has("autocmd") && !has("gui_running"))
|
||||
let s:white = { "gui": "#ABB2BF", "cterm": "145", "cterm16" : "7" }
|
||||
autocmd ColorScheme * call onedark#set_highlight("Normal", { "fg": s:white }) " No `bg` setting
|
||||
end
|
||||
augroup colorset
|
||||
autocmd!
|
||||
let s:white = { "gui": "#ABB2BF", "cterm": "145", "cterm16" : "7" }
|
||||
autocmd ColorScheme * call onedark#set_highlight("Normal", { "fg": s:white }) " `bg` will not be styled since there is no `bg` setting
|
||||
augroup END
|
||||
endif
|
||||
```
|
||||
|
||||
Finally, you can also override a color across all highlights by adding color definitions to the `g:onedark_color_overrides` dictionary in your `~/.vimrc` like so:
|
||||
#### Global color overrides
|
||||
|
||||
You can override colors across all highlights by adding color definitions to the `g:onedark_color_overrides` dictionary in your `~/.vimrc` like so:
|
||||
|
||||
```vim
|
||||
let g:onedark_color_overrides = {
|
||||
|
||||
@@ -71,7 +71,21 @@ endif
|
||||
" Which in turn was based on one found in hemisu: https://github.com/noahfrederick/vim-hemisu/
|
||||
let s:group_colors = {} " Cache of default highlight group settings, for later reference via `onedark#extend_highlight`
|
||||
function! s:h(group, style, ...)
|
||||
let a:highlight = a:0 > 0 ? extend(s:group_colors[a:group], a:style) : a:style
|
||||
if (a:0 > 0) " Will be true if we got here from onedark#extend_highlight
|
||||
let a:highlight = s:group_colors[a:group]
|
||||
for style_type in ["fg", "bg", "sp"]
|
||||
if (has_key(a:style, style_type))
|
||||
let l:default_style = (has_key(a:highlight, style_type) ? a:highlight[style_type] : { "cterm16": "NONE", "cterm": "NONE", "gui": "NONE" })
|
||||
let a:highlight[style_type] = extend(l:default_style, a:style[style_type])
|
||||
endif
|
||||
endfor
|
||||
if (has_key(a:style, "gui"))
|
||||
let a:highlight.gui = a:style.gui
|
||||
endif
|
||||
else
|
||||
let a:highlight = a:style
|
||||
let s:group_colors[a:group] = a:highlight " Cache default highlight group settings
|
||||
endif
|
||||
|
||||
if g:onedark_terminal_italics == 0
|
||||
if has_key(a:highlight, "cterm") && a:highlight["cterm"] == "italic"
|
||||
@@ -98,8 +112,6 @@ function! s:h(group, style, ...)
|
||||
\ "ctermfg=" . l:ctermfg
|
||||
\ "ctermbg=" . l:ctermbg
|
||||
\ "cterm=" (has_key(a:highlight, "cterm") ? a:highlight.cterm : "NONE")
|
||||
|
||||
let s:group_colors[a:group] = a:highlight
|
||||
endfunction
|
||||
|
||||
" public {{{
|
||||
|
||||
Reference in New Issue
Block a user