From 0bcf96bf0bf1136aa4fb09dd86461312a2bc4fbb Mon Sep 17 00:00:00 2001 From: Gregory Anders Date: Thu, 10 Jun 2021 21:59:10 -0600 Subject: fix: source syncolors.vim before startup scripts This fixes an issue (#12573) where colorscheme files are sourced twice upon startup. This occurs when the startup script calls `:colorscheme`, which sets the `g:colors_name` global variable. When syntax highlighting is enabled in `syn_maybe_enable()` the `syntax.vim` script is sourced which in turn sources `synload.vim`. This script checks to see if `g:colors_name` is set and, if so, runs exe "colors " . colors_name This is done to ensure that highlight groups are defined before enabling the syntax highlighting engine. Instead, source syncolors.vim before the startup scripts which sets up default highlights and only load the full syntax engine after the startup scripts or when the user runs `:syntax on`. Add a guard variable `did_syncolor` to prevent syncolor.vim from being sourced twice and remove the line mentioned above from synload.vim so that the colorscheme file is not re-sourced when the syntax engine is loaded. --- runtime/syntax/syncolor.vim | 2 ++ runtime/syntax/synload.vim | 6 ++---- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'runtime/syntax') diff --git a/runtime/syntax/syncolor.vim b/runtime/syntax/syncolor.vim index 5b907a3b83..27cc3360c4 100644 --- a/runtime/syntax/syncolor.vim +++ b/runtime/syntax/syncolor.vim @@ -25,6 +25,8 @@ else endif endif +let did_syncolor = 1 + " Many terminals can only use six different colors (plus black and white). " Therefore the number of colors used is kept low. It doesn't look nice with " too many colors anyway. diff --git a/runtime/syntax/synload.vim b/runtime/syntax/synload.vim index 3863a84c1a..aee9ba8b8e 100644 --- a/runtime/syntax/synload.vim +++ b/runtime/syntax/synload.vim @@ -14,10 +14,8 @@ endif " let others know that syntax has been switched on let syntax_on = 1 -" Set the default highlighting colors. Use a color scheme if specified. -if exists("colors_name") - exe "colors " . colors_name -else +" Set the default highlighting colors +if !exists("colors_name") && !exists("did_syncolor") runtime! syntax/syncolor.vim endif -- cgit