For following snippet of code, to see what was highlighted I need to run :highlight LineHighlight ctermbg=darkgray guibg=drakgray after running vim session, and then rest of snippet works (i.e. loads which lines to highlight etc) , for some reason this one line is not picked up from .vimrc - any hint how to fix it highlight definition so I don't need to type it all over again in gVim ? (it works in Vim)

" define line highlight color
highlight LineHighlight ctermbg=darkgray guibg=darkgray

nnoremap <Leader>l :call matchadd('LineHighlight', '\%'.line('.').'l')<CR>
  • In Vim it just works! ([]+[l] highlights line)
  • In GVim I have to run :highlight LineHighlight ctermbg=darkgray guibg=darkgray to make highlights visible

3 Answers 3


I've had this issue when I set a colour scheme in my gvimrc that cleared all highlighting before setting up its own.

The fix was replace my direct call to :highlight with an autocommand that adds the highlight whenever a colour scheme is set:

augroup CustomColours
  autocmd ColorScheme * highlight LineHighlight ctermbg=darkgray guibg=darkgray
augroup END

Note that for the highlight to also be applied in terminal Vim then you will need to either call :colorscheme after setting up the autocommand, set the highlight explicitly in the vimrc as well as in the autocommand, or trigger the autocommand from the vimrc with :doautocmd.


you could try to add the following line

syntax on

before the line highlight LineHighlight ctermbg=darkgray guibg=darkgray.

to the .vimrc file.

This worked for me.

  • Welcome to Vi and Vim! You might want to prefer :syntax enable
    – D. Ben Knoble
    Commented Aug 1, 2022 at 14:34

You probably need to add the highlight command to your gvimrc, since some things get reset when processing GUI startup.

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.