Override colorscheme
Asked Answered
M

6

33

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
Mickeymicki answered 13/3, 2010 at 21:43 Comment(2)
Why not just copy the theme and edit the copy?Adenovirus
Less work when updating. The idea is to have my changes override the theme's so i can just update the theme without having to merge my changes in.Mickeymicki
N
8

Have a look at AfterColors.vim, it will enable you to to use the ~/.vim/after/colors/BusyBee.vim method.

Newsome answered 9/2, 2011 at 1:32 Comment(1)
Pretty late to this party, but for reference, AfterColors.vim is now mirrored (by me) on Github github.com/tsiemens/vim-aftercolors, such that people can just add it to their plugin list. I just found this thread yesterday, and created that repo. Figured I should make note of it.Michelmichelangelo
H
51

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).

Highmuckamuck answered 12/9, 2011 at 3:37 Comment(4)
Hi, I'm using the jellybeans theme and want to have a pure black backgruond, but it's gray actually. I've added the lines you proposed to the .vimrc, but nothing happens... what do I do?Vibrio
Do you have a transparent terminal? The black background is transparent so you wouldn't get real black if your terminal is transparent. Try :highlight Normal ctermbg=blue during a Vim session and see if it sets your background to blue. If it does, I think you'll have to change your terminal settings. Or maybe there is something that I don't know of.Highmuckamuck
I've tried it and only the first and the last line are set to blue, not the whole window.Vibrio
I had no idea that was possible to autocmd Colorscheme. just my 2 cents, for me the background transparency worked using guibg instead of ctermbg, maybe help some noob like me in the future.Touched
N
8

Have a look at AfterColors.vim, it will enable you to to use the ~/.vim/after/colors/BusyBee.vim method.

Newsome answered 9/2, 2011 at 1:32 Comment(1)
Pretty late to this party, but for reference, AfterColors.vim is now mirrored (by me) on Github github.com/tsiemens/vim-aftercolors, such that people can just add it to their plugin list. I just found this thread yesterday, and created that repo. Figured I should make note of it.Michelmichelangelo
M
4

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'?

Mickeymicki answered 14/3, 2010 at 10:56 Comment(3)
<sarcastic> Yeees, that looks much simpler, for a colorscheme you're using periodically :) ... Btw, if you don't want to change the original file (why?), why not just make a version 2 of it and change it in there. I really don't see why the need for all this problem making out of nothing.Javierjavler
There was no work in doing this compared to the annoyance of "manually" adjusting schemes as you change to them, or bringing along my changes to schemes as i update them (which i would have to manually do if i overwrote it or named it something else). I'm glad for you that you are not as picky about your setup as I am.. ; )Mickeymicki
Wow, great solution! +1 :) I eventually used a "sliced-up" version of this answer. It's based on this one so I didn't want to post a new answer for it. You can view it in my .vimrc: github.com/oryband/dotvim/blob/master/vimrcRascon
S
3

Quoting Vim 8.2 help for posterity as this was my first search hit for this scenario:

To customize a color scheme use another name, e.g. ~/.vim/colors/mine.vim",
and use :runtime to load original color scheme:
    colors/evening.vim
    Statement ctermfg=Blue guifg=Blue
Sandrocottus answered 11/2, 2021 at 16:0 Comment(0)
C
1

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
Convulse answered 5/2, 2016 at 20:43 Comment(3)
Adding after/syntax/syncolor.vim worked for me.Coequal
@JeffSchwab uh, was that a confirmation of the utility of my answer?Convulse
The upvote was confirmation. The comment was to say which part was specifically useful to me.Coequal
J
-4

Put

hi CursorLine    guibg=#000000 ctermbg=Black cterm=none

after your

colorscheme BusyBee

entry in your _vimrc.

Javierjavler answered 13/3, 2010 at 22:25 Comment(1)
@jdhao - You're commenting on an answer from almost ten years ago. A lot has changed since then ...Javierjavler

© 2022 - 2024 — McMap. All rights reserved.