1

Following this great answer when trying to have italic comments in vim, I encounter a strange behaviour: I have those three relevant lines inside my .vimrc:

set t_ZH=^[[3m
set t_ZR=^[[23m
highlight Comment cterm=italic

When I open a file with vim, comments are not displayed in italic. However, if I do :highlight Comment cterm=italic or even :source ~/.vimrc, I get italic comments. Any idea for possible reasons for this?

EDIT: Following the helpful answers, I solved the problem by replacing highlight Comment cterm=italic in my .vimrc with autocmd VimEnter * :highlight Comment cterm=italic.
This article about scripting vim was also helpful.

222
  • 13
  • 4
  • 3
    Your .vimrc commands are likely being overwritten by your colorscheme or a plugin. You could add them to an augroup event to trigger after all buffer load events. – Conner Nov 21 '18 at 15:29
  • @Conner That was my first guess, too. I don't load any colorscheme in my .vimrc and the only two plugins being loaded are `supertab` and `auto-pairs`. Commenting them doesn't change the output. Placing the italics settings at the bottom of vimrc doesn't change anyting. Also, if the italics settings are being overwritten, how is it possible that sourcing vimrc from within vim makes them take effect? Shouldn't they then also being overwritten? – 222 Nov 21 '18 at 16:49
  • 1
    What happens when you specify `vim -u /path/to/my/.vimrc` when starting vim? – Conner Nov 21 '18 at 16:53
  • Comments are upright, as before. Doing `:source ~/.vimrc` gives italic comments. All other settings in `.vimrc` seem to work right away. – 222 Nov 21 '18 at 17:00

1 Answers1

1

It does not have to be a user installed plugin which overwrittes your setting. It could also be a filetype plugin which comes with vim. These filetype specific things are loaded after your .vimrc so they overwrite your settings there. Sourcing your .vimrc afterwards will overwrite them again.

Enter the following command to see where your problem lies:

:verbose hi Comment
Doktor OSwaldo
  • 5,732
  • 20
  • 41
  • Thank you, that did the trick! `:verbose hi Comment` pointed me to line 34 of `/usr/share/vim/vim81/syntax/syncolor.vim`. Changing `cterm=NONE` to `cterm=italic` there solved my problem! – 222 Nov 22 '18 at 09:54
  • Glad to help, but you should not do that. That's the default color file for every user on your system, and may get changed by updates. Have a look at `:help after-directory` or `:h auto-command` or just look on this site https://stackoverflow.com/questions/28375119/override-options-set-by-ftplugins-in-vim – Doktor OSwaldo Nov 22 '18 at 10:33