I often find myself wanting to change just something little in a colorscheme, but i don't want to edit the original file. I tried putting my change in '~/.vim/after/colors/blah.vim', but that doesn't work for me.
Example, I want to change the CursorLine highlight in BusyBee.vim..
~/.vim/colors/BusyBee.vim
I create the file '~/.vim/after/colors/BusyBee.vim' and add this:
hi CursorLine guibg=#000000 ctermbg=Black cterm=none
However, i don't see the change. Of course it works if i change the line in the originial BusyBee.vim, but like i said i'd prefer not to do that.
Doing...
:colo Busy<TAB>
Shows me...
BusyBee BusyBee
Have a look at AfterColors.vim, it will enable you to to use the ~/.vim/after/colors/BusyBee.vim
method.
You asked what I'm looking for today. I found a simpler solution than those presented here. I want transparent background instead of the black background from the theme, while simply overriding the color after the colorscheme
statement in .vimrc
doesn't work and installing a plugin just for that is weird. Here is what I did:
autocmd ColorScheme * highlight Normal ctermbg=None
autocmd ColorScheme * highlight NonText ctermbg=None
Why does it work? I guess that vim does something besides just read your colorscheme
statement and load the statement and then read your highlight
statement and change the color. Anyway it seems like vim only change the color scheme after reading the config files. So I provide a hook, that will change the colors every time the color scheme is changed. A nice side effect is, this works even if you switch your color scheme (you could do an if
block if you want to).
I don't have 'colorscheme BusyBee' in my .vimrc. I like to switch colorscheme now and then, so i want to "fix" the actual theme.
I came up with this solution, not the prettiest, but whatever.
function! FixColorscheme() " {{{
echo "fixing colorscheme"
if has("gui_running")
if (g:colors_name =~ "busybee")
hi Folded guibg=#001336 guifg=#003DAD gui=none
hi CursorLine guibg=#000000 ctermbg=Black cterm=none
elseif (g:colors_name =~ "256-jungle")
hi CursorLine guibg=#000000 ctermbg=Black cterm=none
elseif (g:colors_name =~ "xoria256")
hi Folded guibg=#001336 guifg=#003DAD gui=none cterm=none
"hi Folded ctermbg=234 ctermfg=25 cterm=none
endif
elseif &t_Co == 256
if (g:colors_name =~ "busybee")
hi Folded guibg=#001336 guifg=#003DAD gui=none
hi CursorLine guibg=#000000 ctermbg=Black cterm=none
elseif (g:colors_name =~ "256-jungle")
hi CursorLine guibg=#000000 ctermbg=Black cterm=none
elseif (g:colors_name =~ "xoria256")
hi Folded ctermbg=234 ctermfg=25 cterm=none
hi CursorLine cterm=none
"else
"hi CursorLine ctermbg=0 cterm=none
endif
endif
endfunction
" }}}
Run it automatically when changing color scheme.
augroup mycolorschemes
au!
au ColorScheme * call FixColorscheme()
augroup END
And this helps to load your favorite-scheme-of-the-week on startup. (eek!! the default!)
if iSFirstRun == 1
echo "HI"
colo xoria256
call FixColors()
endif
.. and this at the very top of .vimrc
"" To let us set some settings only once. {{{
if exists("isRunning")
let isFirstRun = 0
else
let isFirstRun = 1
endif
let isRunning = 1
" }}}
Perhaps there already is something for this 'isFirstRun'?
The stock synload.vim
file in $VIM/vimXX/syntax/synload.vim
does a
runtime! syntax/syncolor.vim
This directs vim to read the given filespec in each directory of runtimepath
. On RedHat systems, the runtimepath will be something like:
$HOIME/.vim,/usr/share/vim/vimfiles,/usr/share/vim/vim72,/usr/share/vim/vimfiles/after,$HOME/.vim/after
Put your color adjustments in either $HOME/.vim/after/syntax/syncolor.vim
or in the /usr/share/vim/vimfiles/after/syntax
and you should be good to go.
While your adjustments can be simple hi ...
directives, it's apparently more complicated. So I heavily borrowed from the stock syncolor.vim
file and now have:
if !exists("syntax_cmd") || syntax_cmd == "on"
" ":syntax on" works like in Vim 5.7: set colors but keep links
command -nargs=* SynColor hi <args>
command -nargs=* SynLink hi link <args>
else
if syntax_cmd == "enable"
" ":syntax enable" keeps any existing colors
command -nargs=* SynColor hi def <args>
command -nargs=* SynLink hi def link <args>
elseif syntax_cmd == "reset"
" ":syntax reset" resets all colors to the default
command -nargs=* SynColor hi <args>
command -nargs=* SynLink hi! link <args>
else
" User defined syncolor file has already set the colors.
finish
endif
endif
" Change comment color from bright cyan to gray
" The bold cyan conflicts with variables and other colors
if &background == "dark"
SynColor Comment term=bold cterm=NONE ctermfg=Gray ctermbg=NONE gui=NONE guifg=#80a0ff guibg=NONE
endif
delcommand SynColor
delcommand SynLink
Put
hi CursorLine guibg=#000000 ctermbg=Black cterm=none
after your
colorscheme BusyBee
entry in your _vimrc.