0

Due to various reasons, I run Vim at sixteen-colors, synced w/ my terminal's colors. In a recent Vim update, I've had to rework my "~/.vimrc" completely to get it back into running order on Linux.

Initially I was shocked to find that this simple line did not work (even w/ "syntax on" preceding it):

:highlight Comment ctermfg=White

I'm also using a "LineNr" ctermfg. No matter where I placed/stacked the "Comment" ctermfg, it didn't work, or interfered w/ everything else sourcing correctly (ie, placed in the same line w/ "LineNr"). However, I found that calling "Comment" after a buffer had loaded would make the comments appear as intended.

I am new to autocmd in Vim (and want to know how it works, anyways). Is there an "autocmd" call that I can have in my "~/.vimrc" that will run the aforementioned line of code immediately after a buffer has loaded?

I have tried several iterations (BufWritePre, BufWritePost, etc.) and been unsuccessful. This was my previous attempt:

autocmd BufWinPost * :highlight Comment ctermfg=white
willsy
  • 37
  • 1
  • 7

2 Answers2

0

If I do a quick :h autocmd-events, I find the the event BufWinPost does not exist. I think, you want BufWinEnter instead. The autocmd you wrote should work, except for the :. HTH

mike
  • 131
  • 1
  • 4
0

Don't resort to :autocmd without reason; search harder for the root cause!

Your description lacks specifics; I guess your chosen colorscheme (or a plugin, but no sane plugin should interfere with the default highlightings) overrides your custom one for Comment. You can check who defined this via

:verbose highlight Comment

If this points to your colorscheme, you simply need to execute your :highlight command after it. For this, you need to understand :help initialization, and maybe check the output of :scriptnames. If you have a :colorscheme foo command in your ~/.vimrc, it should be as simple as putting the :highlight command after it.

You do need an :autocmd if you switch colorschemes on the fly, as most colorschemes override the basic Comment definition. The correct event and pattern for that would be ColorScheme *

Ingo Karkat
  • 167,457
  • 16
  • 250
  • 324
  • No, unfortunately I'm not running a "colorscheme" command. As stated, I have simply synced vim up to my terminal's sixteen-color palette and manipulated Vim's syntax from there whether manually thru "~/.vimrc" or otherwise. However, your instruction to utilize ":verbose" solved the problem. Somehow the "syntax.vim" file's "ctermfg" file was changed to colors that I didn't want. Thx! – willsy Apr 24 '17 at 21:31
  • "syncolor.vim," not "syntax.vim". My apologies. – willsy Apr 24 '17 at 21:58
  • Ah, great you've figured it out! – Ingo Karkat Apr 25 '17 at 11:47