Lightline.vim: Switching between solarized dark and light?

Created on 14 Aug 2016  路  6Comments  路  Source: itchyny/lightline.vim

In the past there used to be separate colour schemes for solarized light and dark, but now there is only one. I use the flattened colour scheme, which is basically Solarized without all the tacked-on nonsense and it works with Neovim's true colour support (the official Solarized doesn't). But how can I change the variant used by Lightline?

I have followed the documentation which says to write a function like this:

function! s:lightline_update()
    if !exists('g:loaded_lightline')
        return
    endif
    try
        if g:colors_name =~# 'wombat\|solarized\|landscape\|jellybeans\|Tomorrow'
            let g:lightline.colorscheme =
                \ substitute(substitute(g:colors_name, '-', '_', 'g'), '256.*', '', '') .
        elseif g:colors_name =~# 'flattened_dark'
            let g:lightline.colorscheme = 'solarized'
        elseif g:colors_name =~# 'flattened_light'
            let g:lightline.colorscheme = 'solarized'
        endif
        call lightline#init()
        call lightline#colorscheme()
        call lightline#update()
    catch
    endtry
endfunction

I tried adding set background=dark/set background=light above the lines with let g:lightline.colorscheme = 'solarized', but that doesn't do anything. When I try Vim with the official Solarized colour scheme the same thing happens. Lightline only accepts the first time that background is set (i.e. in my vimrc), but not changes to it afterwards.

question

Most helpful comment

Sure, here's my lightline_update:

function! s:lightline_update()
        if !exists('g:loaded_lightline')
                return
        endif
        try
                if g:colors_name =~# 'solarized'
                        runtime autoload/lightline/colorscheme/solarized.vim
                        call lightline#init()
                        call lightline#colorscheme()
                        call lightline#update()
                endif
        catch
        endtry
endfunction

All 6 comments

Sorry but what you want is not supported anymore. I dropped the support because most people do not switch the colorsheme while editting source code. Please restart the editor to see the appearance changes.

Not really what I was hoping for, but OK. The problem is that most of the time I'm working in dark mode, but sometimes the sun outside is too bright, so I want to switch to light mode during work. Restarting my editor would mean I have to first edit my vimrc and then restart. I think it will be the easiest to just add a separate light and dark colorscheme to flattened instead of using Lightline's Solarized, even though they are the same colours.

I solved this problem by adding a "runtime autoload/lightline/colorscheme/solarized.vim" before the calls to lightline#init() etc. in the lightline_update() function. It may be ugly, but it works for me.

@eyvind Would you mind sharing how you've performed the edits? Switching between light and dark is also important to me, but I cannot figure out how you've done it.

Sure, here's my lightline_update:

function! s:lightline_update()
        if !exists('g:loaded_lightline')
                return
        endif
        try
                if g:colors_name =~# 'solarized'
                        runtime autoload/lightline/colorscheme/solarized.vim
                        call lightline#init()
                        call lightline#colorscheme()
                        call lightline#update()
                endif
        catch
        endtry
endfunction

Thanks, works like a charm!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

linus345 picture linus345  路  3Comments

kbc8090 picture kbc8090  路  3Comments

ayutheos picture ayutheos  路  4Comments

Blosberg picture Blosberg  路  4Comments

ahmedelgabri picture ahmedelgabri  路  3Comments