augroup filetype_colorscheme
au BufEnter *
\ if !exists('b:colors_name')
\ | if &ft == "vim"
\ | let b:colors_name = 'color_dark'
\ | else
\ | let b:colors_name = 'color_light'
\ | endif
\ | endif
\ | exe 'colorscheme' b:colors_name
augroup END
However, it doesn't work fine in split windows.
When I click on a .vim file in the split window all not .vim files changes to the dark colorscheme as well.
I would like to keep them their own colorscheme; a .vim page always the dark colorscheme and whatever other file always the light colorscheme.
I've learned that colorschemes will always affect the entire vim instance and that it is not possible to have a different color scheme per split window.
In that point I would like to disable above code for split windows in order to give all split windows the default colorscheme (which I can change afterwards using :color "colorscheme") but don't know how to realize this. Whatever I tried didn't do what I want it to do.
Can anyone help me?
You can check the number of windows with winnr('$'). If > 1, you have multiple split windows.
Hi Ben,
That's what I tried.
But wherever I put it in above code it doesn't work.
Where would you place this in above code?
Thank you very much.
Just one little thing..
What I noted is that when I have a split window it gives the default colorscheme (that's ok) but I would like to have the possibility to change the colorscheme of all split buffers in a window with the :color "colorscheme" command (and if possible keep this colorscheme when I switch from one Tab to another and back to the split window or when I click in another split buffer in the split window.
(when I have multiple .vim files in the split window I prefer the dark colorscheme, when I have multiple .txt files in the split, I prefer the light colorscheme. That isn't possible now. When I use :color "colorscheme" and click in another split window all other split windows changes again to the default colorscheme)
Is it possible to do?
Yes I mean another window in the current tab.
But after an hour of reading help-files I don't have an idea how to adapt the script, sorry.
Can't find the solution.
I tried to change g:colors-name in w/t/s/b:colors-name but nothing works.
Tony or anyone else, any idea?
I created the function below.
The function must do this (and seems to do it):
a) when there is only 1 window:
check if filetype is "vim" --> Dark_ColorScheme
if filetype is not "vim" --> Light_ColorScheme
b) when there is a split window:
check if exist split window colorscheme variable (g:splitcolor)
if yes, colorscheme of splitwindow = g:splitcolor
when leaving split window:
keep the value of the current color in g:splitcolor
Can anyone tell me if I made a mistake and if the function can be simplified?
function SetColors()
if winnr('$') > 1
if exists('g:splitcolor')
exe 'colors '.g:splitcolor
else
exe 'colors Light_ColorScheme'
endif
elseif winnr('$') == 1 && &ft == 'vim'
exe 'colors Dark_ColorScheme'
elseif winnr('$') == 1 && &ft != 'vim'
exe 'colors Light_ColorScheme'
endif
endfunction
function KeepColors()
if winnr('$') > 1
let g:splitcolor = g:colors_name
endif
endfunction
augroup filetype_colorscheme
au BufEnter * call SetColors()
au BufLeave * call KeepColors()
augroup END
Looks like it should do what you want, just fine. A minor note, you don't need the exe if you're providing the colorscheme name literally, e.g. "exe 'colors Dark_ColorScheme'" could be just "colors Dark_ColorScheme", but that's not really an important detail; it should work fine as-is.