1

To make the usage of vim in cygwin convenient, I've added the color scheme in my cygwin .vimrc. But I found the color scheme doesn't work when vim is started.

So I did some investigations:

  1. My Cygwin indeed support xterm-256color. This is 256 color test script: xterm xterm2
  2. The Comment highlight style indeed setup in the .vimrc:
    hi Comment ctermfg=239
  3. But the final Comment color scheme was loaded from /usr/share/vim/vim74/syntax/syncolor.vim vim-verbose
  4. My .vimrc was indeed sourced, but the color part was replaced by syncolor.vim. Because syncolor.vim is sourced twice, and it's sourced at the end of vim startup. I'm using the # vim -u ~/.cygwin/.vimrc --startuptime startup.log to check the startup scripts as below:

    times in msec
     clock   self+sourced   self:  sourced script
     clock   elapsed:              other lines

    000.003  000.003: --- VIM STARTING ---
    000.076  000.073: Allocated generic buffers
    000.124  000.048: locale set
    000.127  000.003: clipboard setup
    000.130  000.003: window checked
    007.568  007.438: inits 1
    007.576  000.008: parsing arguments
    007.577  000.001: expanding arguments
    007.623  000.046: shell init
    008.543  000.920: Termcap init
    008.562  000.019: inits 2
    008.791  000.229: init highlight
    016.569  001.641  001.641: sourcing /usr/share/vim/vim74/syntax/syncolor.vim
    017.190  003.695  002.054: sourcing /usr/share/vim/vim74/syntax/synload.vim
    043.658  024.373  024.373: sourcing /usr/share/vim/vim74/filetype.vim
    044.007  032.170  004.102: sourcing /usr/share/vim/vim74/syntax/syntax.vim
    045.527  000.074  000.074: sourcing /usr/share/vim/vim74/filetype.vim
    047.319  000.182  000.182: sourcing /usr/share/vim/vim74/ftplugin.vim
    049.047  000.151  000.151: sourcing /usr/share/vim/vim74/indent.vim
    049.926  039.919  007.342: sourcing /cygdrive/c/Users/310258281/.cygwin/.vimrc
    049.947  001.237: sourcing vimrc file(s)
    053.216  001.338  001.338: sourcing /usr/share/vim/vimfiles/plugin/fzf.vim
    058.199  000.224  000.224: sourcing /usr/share/vim/vim74/plugin/getscriptPlugin.vim
    060.159  000.664  000.664: sourcing /usr/share/vim/vim74/plugin/gzip.vim
    061.716  000.449  000.449: sourcing /usr/share/vim/vim74/plugin/logiPat.vim
    062.920  000.166  000.166: sourcing /usr/share/vim/vim74/plugin/manpager.vim
    064.748  000.545  000.545: sourcing /usr/share/vim/vim74/plugin/matchparen.vim
    067.242  001.156  001.156: sourcing /usr/share/vim/vim74/plugin/netrwPlugin.vim
    068.456  000.122  000.122: sourcing /usr/share/vim/vim74/plugin/rrhelper.vim
    069.628  000.137  000.137: sourcing /usr/share/vim/vim74/plugin/spellfile.vim
    071.121  000.530  000.530: sourcing /usr/share/vim/vim74/plugin/tarPlugin.vim
    072.821  000.264  000.264: sourcing /usr/share/vim/vim74/plugin/tohtml.vim
    074.253  000.478  000.478: sourcing /usr/share/vim/vim74/plugin/vimballPlugin.vim
    075.695  000.465  000.465: sourcing /usr/share/vim/vim74/plugin/zipPlugin.vim
    075.716  019.231: loading plugins
    077.403  001.687: loading packages
    077.839  000.436: loading after plugins
    077.851  000.012: inits 3
    078.628  000.777: reading viminfo
    078.634  000.006: setting raw mode
    078.652  000.018: start termcap
    078.724  000.072: clearing screen
    090.187  011.463: opening buffers
    090.254  000.067: BufEnter autocommands
    090.263  000.009: editing files in windows
    092.323  000.474  000.474: sourcing /usr/share/vim/vim74/syntax/syncolor.vim
    094.458  003.721: VimEnter autocommands
    094.464  000.006: before starting main loop
    094.627  000.163: first screen update
    094.630  000.003: --- VIM STARTED ---

So simply speaking, vim works as below:


 016.569  001.641  001.641: sourcing /usr/share/vim/vim74/syntax/syncolor.vim
 049.926  039.919  007.342: sourcing /cygdrive/c/Users/310258281/.cygwin/.vimrc
 092.323  000.474  000.474: sourcing /usr/share/vim/vim74/syntax/syncolor.vim

Why's that?

Oh, by the way, my environment:

  • OS: Win10 64bit
  • Cygwin: mintty 2.6.2 (x86-64-pc-cygwin)
  • Vim in Cygwin: version 7.4.2367, Modified by
1
  • It looks like you have some VimEnter autocommands there. I wonder what they are.
    – Antony
    Nov 18, 2016 at 14:44

2 Answers 2

3

There's a simpler workaround. Just add let g:syntax_cmd = "skip" to your .vimrc.

From :h syntax_cmd:

The "syntax_cmd" variable is set to one of these values when the
syntax/syncolor.vim files are loaded:
   "on"     ":syntax on" command.  Highlight colors are overruled but
        links are kept
   "enable" ":syntax enable" command.  Only define colors for groups that
        don't have highlighting yet.  Use ":syntax default".
   "reset"  ":syntax reset" command or loading a color scheme.  Define all
        the colors.
   "skip"   Don't define colors.  Used to skip the default settings when a
        syncolor.vim file earlier in 'runtimepath' has already set
        them.

syncolors.vim checks if syntax_cmd is set. If it's set to "skip", it exits without changing any of your settings.

1
  • Thanks @Ray very much!! This is the perfect solution!!! I'm using the let syntax_cmd = "enable" in my .vimrc, I want colors defined by myself shows the color which it defined. And the groups shows default which I haven't been defineded.
    – Marslo
    Feb 9, 2017 at 7:50
2

Okay, Okay, I found the reason. There's code shows in /usr/share/vim/vim74/syntax/synload.vim: vim2

$ cat -n /usr/share/vim/vim74/syntax/synload.vim


...
    17  " Set the default highlighting colors.  Use a color scheme if specified.
    18  if exists("colors_name")
    19    exe "colors " . colors_name
    20  else
    21    runtime! syntax/syncolor.vim
    22  endif
...

Which means, if there's no colorcheme defined in vimrc, so the syncolor.vim will be the default one.... No wonder the syncolor.vim are loaded twice.

So, a simple workaround, add colorscheme xxx in the vimrc, it will prevent syncolor.vim re-load, and also my colorscheme will replace the color name set in vimrc: vim3

5
  • Why don't you move your highlight commands to a proper colorscheme?
    – romainl
    Oct 19, 2016 at 5:55
  • I'm using Cygwin and Gitbash at the same time. If I'm using the colorscheme, then this file has to be copy to both git and cygwin folders, which means, if I want to change anything in git colorscheme file, then I have to sync change to cygwin vim colorscheme file again. If the colorscheme file set in ~/.vim, my windows gvim will get impacted. I'm using the gvim.exe most of time, I don't want to wast many times to mantain vimrc in cygwin/git bash
    – Marslo
    Oct 19, 2016 at 7:56
  • synload.vim sources syncolor.vim the first time. I doubt it's responsible for the second one.
    – Antony
    Nov 18, 2016 at 14:45
  • I can't reproduce this using the information you've supplied, by the way.
    – Antony
    Nov 18, 2016 at 14:52
  • @Antony are you using cygwin?
    – Marslo
    Dec 21, 2016 at 3:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.