0

I customed comment and search highlight in my vimrc, but they are not effective every time I entered vim. I have to source vimrc to make them effective. How can I make them always effective?

highlight PMenu ctermfg=225 ctermbg=60 guifg=black guibg=darkgrey
highlight PMenuSel ctermfg=242 ctermbg=225 guifg=darkgrey guibg=black
highlight Comment ctermfg=104 ctermbg=none
highlight Search ctermfg=116 ctermbg=211

syntax enable
1
  • Can we see the rest of your vimrc?
    – romainl
    Commented Jul 31, 2023 at 8:51

1 Answer 1

1

While it's hard to tell without more information, I suspect you want to use a ColorScheme autcommand to have the changes applied whenever a colorscheme is applied:

function MyHighlight() abort
  highlight PMenu ctermfg=225 ctermbg=60 guifg=black guibg=darkgrey
  highlight PMenuSel ctermfg=242 ctermbg=225 guifg=darkgrey guibg=black
  highlight Comment ctermfg=104 ctermbg=none
  highlight Search ctermfg=116 ctermbg=211
endfunction

augroup colors | autocmd!
  autocmd ColorScheme * call MyHighlight()
augroup end

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.