The issue
Consider the following two Vimrc configuration lines for the YouCompleteMe plugin:
au BufRead, BufNewFile *.py,*.pyw match BadWhitespace /\s\+$/
au FileType python match BadWhitespace /\s\+$/
When opening an existing file (vim somefile.py
), the first one loads and works correctly (wrong whitespace gets highlighted), while the second one results in the following error message but the functionality still works correctly (wrong whitespace gets highlighted):
Error detected while processing BufRead Autocommands for "*.py"..FileType Autocommands for "python":
E28: No such highlight group name: BadWhitespace
Questions
This issue is confusing on so many aspects...
- Based on the Q&A linked below, I understood that the two main differences between
BufRead+BufNewFile
vsFileType
are the following:
BufRead+BufNewFile
does not affect writing to an existing fileFileType
is not aware of all file formats
However, neither of these explains the reported behavior, because FileType
is, in fact, aware of Python files, and in this case we are not writing a file (but reading one).
Why does the functionality still work in spite of the error message?
The error message is slightly confusing, because it talks about
BufRead Autocommands
, whereas the used keyword wasFileType
(and there is no error message whenBufRead
is used for real). So isFileType
just a wrapper aroundBufRead
?
Remark
As stated, I am aware of this Question and the related Answers (1, 2), but as I mentioned, they don't explain the case above. So I believe this is some kind of an edge case and hence a new question is appropriate.
BufRead,
andBufNewFile
really there or is it just a typo in your question?