Quantcast

Colorschemes and split window

classic Classic list List threaded Threaded
13 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Colorschemes and split window

rameo
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 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
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Colorschemes and split window

Ben Fritz
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.

--
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
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Colorschemes and split window

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

--
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
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Colorschemes and split window

Tony Mechelynck
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
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Colorschemes and split window

Gary Johnson-4
Minor correction.

On 2012-04-27, Tony Mechelynck wrote:
> On 27/04/12 18:34, rameo wrote:

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

Regards,
Gary

--
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
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Colorschemes and split window

rameo
In reply to this post by Tony Mechelynck
On Friday, April 27, 2012 8:29:03 PM UTC+2, Tony Mechelynck wrote:

> 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"

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?

--
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
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Colorschemes and split window

Tony Mechelynck
On 27/04/12 23:41, rameo wrote:

> On Friday, April 27, 2012 8:29:03 PM UTC+2, Tony Mechelynck wrote:
>> 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"
>
> 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?
>

Well, it is possible, with a slight refinement to the above. You may
want to remember the Vim terminology:

- buffer: one file (or file-like data) in Vim memory, with the relevant
metadata. It may be displayed in zero or more windows.
- window: a viewport into a buffer. If several windows display the same
buffer, changes made in one are reflected in all others. Also, if
several windows display the same buffer, the displayed regions of that
buffer may or may not overlap.
- tab page: a set of one or more windows which are displayed at the same
time.

"another split buffer in a split window" has no meaning. Maybe you meant
"another window in the current tab"?

You can use variables with different scopes:

b:something local to a buffer
g:something global to all Vim
l:something local to a function
s:something local to a script
t:something local to a tab page
v:something predefined at compile-time
w:something local to a window

With no prefix it falls back to v: for compatibility for a few
predefined names, otherwise l: if inside a function, otherwise g:

See also the help for the following functions:

bufname()
bufnr()
bufwinnr()
tabpagebuflist()
tabpagenr()
tabpagewinnr()
winbufnr()
winnr()

See also |setting-tabline| for an example of how to use these functions
(albeit for a different purpose).


Best regards,
Tony.
--
Ten million Linux users can't be wrong!

--
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
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Colorschemes and split window

rameo
On Saturday, April 28, 2012 12:39:51 AM UTC+2, Tony Mechelynck wrote:

> On 27/04/12 23:41, rameo wrote:
> > On Friday, April 27, 2012 8:29:03 PM UTC+2, Tony Mechelynck wrote:
> >> 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"
> >
> > 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?
> >
>
> Well, it is possible, with a slight refinement to the above. You may
> want to remember the Vim terminology:
>
> - buffer: one file (or file-like data) in Vim memory, with the relevant
> metadata. It may be displayed in zero or more windows.
> - window: a viewport into a buffer. If several windows display the same
> buffer, changes made in one are reflected in all others. Also, if
> several windows display the same buffer, the displayed regions of that
> buffer may or may not overlap.
> - tab page: a set of one or more windows which are displayed at the same
> time.
>
> "another split buffer in a split window" has no meaning. Maybe you meant
> "another window in the current tab"?
>
> You can use variables with different scopes:
>
> b:something local to a buffer
> g:something global to all Vim
> l:something local to a function
> s:something local to a script
> t:something local to a tab page
> v:something predefined at compile-time
> w:something local to a window
>
> With no prefix it falls back to v: for compatibility for a few
> predefined names, otherwise l: if inside a function, otherwise g:
>
> See also the help for the following functions:
>
> bufname()
> bufnr()
> bufwinnr()
> tabpagebuflist()
> tabpagenr()
> tabpagewinnr()
> winbufnr()
> winnr()
>
> See also |setting-tabline| for an example of how to use these functions
> (albeit for a different purpose).
>
>
> Best regards,
> Tony.
> --
> Ten million Linux users can't be wrong!

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.

--
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
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Colorschemes and split window

rameo
In reply to this post by Tony Mechelynck
On Saturday, April 28, 2012 12:39:51 AM UTC+2, Tony Mechelynck wrote:

> On 27/04/12 23:41, rameo wrote:
> > On Friday, April 27, 2012 8:29:03 PM UTC+2, Tony Mechelynck wrote:
> >> 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"
> >
> > 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?
> >
>
> Well, it is possible, with a slight refinement to the above. You may
> want to remember the Vim terminology:
>
> - buffer: one file (or file-like data) in Vim memory, with the relevant
> metadata. It may be displayed in zero or more windows.
> - window: a viewport into a buffer. If several windows display the same
> buffer, changes made in one are reflected in all others. Also, if
> several windows display the same buffer, the displayed regions of that
> buffer may or may not overlap.
> - tab page: a set of one or more windows which are displayed at the same
> time.
>
> "another split buffer in a split window" has no meaning. Maybe you meant
> "another window in the current tab"?
>
> You can use variables with different scopes:
>
> b:something local to a buffer
> g:something global to all Vim
> l:something local to a function
> s:something local to a script
> t:something local to a tab page
> v:something predefined at compile-time
> w:something local to a window
>
> With no prefix it falls back to v: for compatibility for a few
> predefined names, otherwise l: if inside a function, otherwise g:
>
> See also the help for the following functions:
>
> bufname()
> bufnr()
> bufwinnr()
> tabpagebuflist()
> tabpagenr()
> tabpagewinnr()
> winbufnr()
> winnr()
>
> See also |setting-tabline| for an example of how to use these functions
> (albeit for a different purpose).
>
>
> Best regards,
> Tony.
> --
> Ten million Linux users can't be wrong!

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?

--
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
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Colorschemes and split window

rameo
In reply to this post by rameo
It seems that I have found the solution (after many many hours of trying :-( )

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

--
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
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Colorschemes and split window

Ben Fritz
On Monday, April 30, 2012 8:15:26 AM UTC-5, rameo wrote:

> It seems that I have found the solution (after many many hours of trying :-( )
>
> 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.

--
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
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Colorschemes and split window

Khaled Ahsan Talukder
In reply to this post by rameo
H

On Monday, April 30, 2012 9:15:26 AM UTC-4, rameo wrote:

> It seems that I have found the solution (after many many hours of trying :-( )
>
> 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

Hi,

I am trying to achieve similar goal, I want to have different color schemes for different file types, but I use omnicppcomplete, which opens a floating window for auto-completion. So, when I try to do the autocompletion, the whole color scheme reverts back to the default. Have you found any work around?

--
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
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Colorschemes and split window

Ben Fritz
On Saturday, September 22, 2012 1:18:23 AM UTC-5, ramgorur wrote:

> H
>
> On Monday, April 30, 2012 9:15:26 AM UTC-4, rameo wrote:
> > It seems that I have found the solution (after many many hours of trying :-( )
> >
> > 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
>
> Hi,
>
> I am trying to achieve similar goal, I want to have different color schemes for different file types, but I use omnicppcomplete, which opens a floating window for auto-completion. So, when I try to do the autocompletion, the whole color scheme reverts back to the default. Have you found any work around?

What do you mean by "floating window"? The best workaround would probably be to detect this type of window in your function and take no action if detected. Is it just the "preview window"? If so, testing for &previewwindow should do it. Does it have a special &buftype value? Or a special &filetype value? These could be tested as well.

I suspect you're talking about the preview window, since you're using completion. If you have "preview" in your 'completeopts' option, you will automatically see the preview window pop up for completion methods which supply the required information.

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