preservim / vim-indent-guides

A Vim plugin for visually displaying indent levels in code
MIT License
2.64k stars 164 forks source link

Guides not showing up the first time with colorscheme desert #109

Open shikhanshu opened 8 years ago

shikhanshu commented 8 years ago

Here's my .vimrc snippet: let g:indent_guides_start_level=2 let g:indent_guides_guide_size=1 let g:indent_guides_enable_on_vim_startup=1 colorscheme desert set background=dark

When I was on a different colorscheme (gruvbox), guides showed up just fine when opening up vim for the first time.

But now, with the desert colorscheme, the first time guides don't show up, but when I set background to dark again (even though it is already set to dark in vimrc) within vim, they show up.

What's happening?

jerrylipeng commented 8 years ago

I got the same issue.

I found that when vim starts, "let s:hi_normal = indent_guides#capture_highlight('Normal')" will get Normal xxx guifg=gray guibg=grey17 font=Monospace 10 Then in indent_guides#gui_highlight_colors, "let l:color_name = matchstr(s:hi_normal, s:color_name_bg_pat)" will get "grey17 10". So "let l:hi_normal_guibg = color_helper#color_name_to_hex(l:color_name)" gets an empty value.

if ":colorscheme desert", "indent_guides#capture_highlight('Normal')" returns "Normal xxx guifg=gray guibg=grey17", and the plugin works fine.

My workaround is: change let g:indent_guides_color_name_guibg_pattern = "guibg='\?\zs[0-9A-Za-z ]+\ze'\?" to let g:indent_guides_color_name_guibg_pattern = "guibg='\?\zs[0-9A-Za-z]+\ze'\?" (Remove the space)

shikhanshu commented 8 years ago

Any fix for this issue? I really like 'desert'. With other colorschemes (like molokai), indent guides show up right on cue as soon as I start vim with a file.

jerrylipeng commented 8 years ago

You can try my workaround. Works for me.

haolly commented 8 years ago

same with you

rahultadak commented 7 years ago

Yes, this worked for me too.

dragon-architect commented 2 years ago

I've just had to resurrect my github account to comment that I am experiencing this exact same issue, but weirdly enough only in gVim. I'm using gVim 8.1, and the Desert colorscheme. I've already attempted jerrylipeng's workaround to no avail. I had to dig manually through the script files of this plugin to figure out which color it grabs from the color scheme and how it actually computes the highlight values to come up with this manual workaround that only applies to my version of the desert colorscheme:

First, :hi Normal returns a string that includes guibg=grey20, which is the color the script is supposed to grab (but it's also followed by the font info that jerrylipeng identifies as well).

Checking the color_helper.vim script indicates grey20 = #333333. From there, I manually applied the color_helper#hex_color_lighten(color, percent) function with a calculator to get the values needed for this code snippet now in my .vimrc:

if has("gui_running")
    if g:colors_name =~ "desert"
        autocmd VimEnter,Colorscheme * :hi IndentGuidesOdd  guibg=#474747
        autocmd VimEnter,Colorscheme * :hi IndentGuidesEven guibg=#606060
    endif
endif

If jerrylipeng's workaround doesn't work for you, you may want to try this more manual fix until the plugin gets updated to fix this bug with the desert color scheme.