1

The following line in my ~/.vimrc:

hi Comment ctermfg=gray

does not take effect unless I start Vim and then use :source to reload .vimrc. As far as I can tell, all of the other hi commands work without reloading .vimrc. What could be causing this?

This is my full .vimrc:

filetype indent plugin on                                                       
syntax on                                                                       

set number                                                                      
set relativenumber                                                              

set colorcolumn=80                                                              

set showcmd                                                                     

set expandtab                                                                   
set shiftwidth=4                                                                
set smarttab                                                                    

set list                                                                        
set listchars=tab:>-,trail:~                                                    

hi ColorColumn ctermbg=0                                                        
hi LineNr ctermfg=gray                                                          
hi CursorLineNr ctermfg=gray                                                    
hi Comment ctermfg=gray                                                         
hi Function ctermfg=darkgreen                                                   

hi pythonStatement ctermfg=lightblue                                            
hi pythonConditional ctermfg=lightblue                                          
hi pythonRepeat ctermfg=lightblue                                               
hi pythonException ctermfg=lightblue                                            
hi pythonDecoratorName ctermfg=lightblue                                        
let python_no_number_highlight = 1                                                                                                               

Edit: The output of :verbose hi Comment is:

Comment        xxx term=bold ctermfg=14 guifg=#80a0ff
        Last set from /usr/share/vim/vim80/syntax/syncolor.vim

So it appears that my setting is being overridden by the default syntax file. I will investigate how to solve this when I have time, but would appreciate any tips from more experienced users :)

  • 2
    What’s the output of :verbose hi Comment? – Rich Feb 11 at 23:39
  • 2
    Welcome to Vi and Vim! As Rich said, it would be great if you edit the results of the command :verbose hi Comment into your question – D. Ben Knoble Feb 12 at 2:31
  • @D.BenKnoble Done. – jth Feb 13 at 6:26
1

I can confirm this with the latest vim-nightly.

  1. your vimrc loads first (where you have defined your highlighing)
  2. then syntax/synload.vim does override it with:
" Set the default highlighting colors.  Use a color scheme if specified.
if exists("colors_name")
  exe "colors " . colors_name
else
  runtime! syntax/syncolor.vim
endif

where syntax/syncolor.vim is the one that defines default colors.

I have tried to setup:

let g:colors_name = "mycolorscheme"
let colors_name = "mycolorscheme"
hi Comment guibg=green

But it still thinks colors_name doesn't exist.

Back to solution: Solution 1

I would suggest to create your own colorscheme .vim/colors/mycolorscheme.vim

set background=light

hi clear
if exists('syntax_on')
    syntax reset
endif

let g:colors_name = 'mycolorscheme'

hi ColorColumn ctermbg=0                                                        
hi LineNr ctermfg=gray                                                          
hi CursorLineNr ctermfg=gray                                                    
hi Comment ctermfg=gray                                                         
hi Function ctermfg=darkgreen                                                   

hi pythonStatement ctermfg=lightblue                                            
hi pythonConditional ctermfg=lightblue                                          
hi pythonRepeat ctermfg=lightblue                                               
hi pythonException ctermfg=lightblue                                            
hi pythonDecoratorName ctermfg=lightblue

and in your vimrc use it:

filetype indent plugin on                                                       
syntax on                                                                       

set number                                                                      
set relativenumber                                                              

set colorcolumn=80                                                              

set showcmd                                                                     

set expandtab                                                                   
set shiftwidth=4                                                                
set smarttab                                                                    

set list                                                                        
set listchars=tab:>-,trail:~ 

let python_no_number_highlight = 1

colorscheme mycolorscheme

Solution 2

Just add colorscheme default before your highlight definitions:

filetype indent plugin on                                                       
syntax on                                                                       

set number                                                                      
set relativenumber                                                              

set colorcolumn=80                                                              

set showcmd                                                                     

set expandtab                                                                   
set shiftwidth=4                                                                
set smarttab                                                                    

set list                                                                        
set listchars=tab:>-,trail:~                                                    

colorscheme default

hi ColorColumn ctermbg=0                                                        
hi LineNr ctermfg=gray                                                          
hi CursorLineNr ctermfg=gray                                                    
hi Comment ctermfg=gray                                                         
hi Function ctermfg=darkgreen                                                   

hi pythonStatement ctermfg=lightblue                                            
hi pythonConditional ctermfg=lightblue                                          
hi pythonRepeat ctermfg=lightblue                                               
hi pythonException ctermfg=lightblue                                            
hi pythonDecoratorName ctermfg=lightblue                                        
let python_no_number_highlight = 1  

PS, looks like colorscheme command does smth that sets up colors_name variable properly?

| improve this answer | |
  • Solution 1 (creating my own colorscheme) worked for me, thanks! – jth Mar 14 at 0:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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