Friday, April 27, 2012

Re: Colorschemes and split window

On 27/04/12 18:34, rameo wrote:
> On Friday, April 27, 2012 6:18:29 PM UTC+2, Ben Fritz wrote:
>> On Friday, April 27, 2012 10:56:55 AM UTC-5, rameo wrote:
>>> I use this code in my .vimrc to use my dark colorscheme when I open a .vim page and my light colorscheme when I open whatever other page:
>>>
>>> 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?
>

Around your autocommand:

augroup filetype_colorscheme
au BufEnter *
\ if winnr('$') == 1
\ | 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
\ | else
\ | colorscheme default
| | endif
augroup END

or (maybe more readable)

function SetColors()
if exists('b:colors_name')
exe 'colorscheme' b:colors_name
return
endif
if winnr('$') > 1
colorscheme default
elseif &ft == 'vim'
colorscheme color_dark
else
colorscheme color_light
endif
let b:colors_name = g:colors_name
endfunction
augroup filetype_colorscheme
au BufEnter * call SetColors()
augroup END

This way, the autocommand will be defined unconditionally, but if it
finds that at BufEnter three are more than one window in the current tab
it will go back to the default scheme.


Best regards,
Tony.
--
Actor: So what do you do for a living?
Doris: I work for a company that makes deceptively shallow serving
dishes for Chinese restaurants.
-- Woody Allen, "Without Feathers"

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

No comments:

Post a Comment