octol / vim-cpp-enhanced-highlight

Additional Vim syntax highlighting for C++ (including C++11/14/17)
MIT License
1.06k stars 149 forks source link

Error in processing syntax/cpp.vim. #63

Closed mananaBanana closed 6 years ago

mananaBanana commented 6 years ago

On a fresh install (using pathogen), I get an error whenever I open a .cpp file.

Error detected while processing [path to syntax]/after/syntax/cpp.vim:
line 61:
E28: No such highlight group name: cppStructure.

The error goes away on commenting line 61.

" syn clear cppStructure

But if I do that none of the additional features, like member highlighting, work. I have had a look at Issue #26 and #53 but the solutions listed there don't seem to help.

bfrg commented 6 years ago

The highlight group cppStructure is set in Vim's default cpp syntax file. You can find it under $VIMRUNTIME/syntax/cpp.vim, or on github.

Run :scriptnames to see what files were sourced on startup. If that file isn't sourced, you don't get any default c++ syntax highlighting.

mananaBanana commented 6 years ago

If I run :scriptnames, I can see both /usr/share/vim/vim80/syntax/cpp.vim and ~/.vim/bundle/syntax/after/syntax/cpp.vim being loaded. But I think first file is loaded after the latter (I'm assuming :scriptnames lists in the order in which the files are loaded.) Can that be the reason behind the error?

  1: ~/.vimrc
  2: /usr/share/vim/vim80/filetype.vim
  3: /usr/share/vim/vim80/ftplugin.vim
...
 34: /usr/share/vim/vim80/indent/cpp.vim
 35: ~/.vim/bundle/syntax/after/syntax/cpp.vim
 36: /usr/share/vim/vim80/syntax/cpp.vim
 37: ~/.vim/bundle/syntax/after/syntax/c.vim
 38: /usr/share/vim/vim80/syntax/c.vim
bananartist commented 6 years ago

The problem indeed comes from the fact that your vim80/syntax/c*.vim files are loaded after. To resolve this, I simply did the following:

$> cd ~/.vim/bundle/
$> git clone https://github.com/octol/vim-cpp-enhanced-highlight.git
mananaBanana commented 6 years ago

I removed the ~/.vim/syntax/ folder and followed what @MrBananane said, but the error still comes up. :scriptnames now reads:

 37: /usr/share/vim/vim80/indent/cpp.vim
 38: ~/.vim/bundle/vim-cpp-enhanced-highlight/after/syntax/cpp.vim
 39: /usr/share/vim/vim80/syntax/cpp.vim
 40: ~/.vim/bundle/vim-cpp-enhanced-highlight/after/syntax/c.vim
 41: /usr/share/vim/vim80/syntax/c.vim
mananaBanana commented 6 years ago

Fixed this by setting the order of directories in runtimepath in my .vimrc file. I had appended /usr/share/vim/vim80 directory after upgrading to vim 8.0 and messed up the order. Original:

set runtimepath=~/.vim,/var/lib/vim/addons,/usr/share/vim/vimfiles,/usr/share/vim/vimfiles/after,/var/lib/vim/addons/after,~/.vim/after,/usr/share/vim/vim80,

Fixed:

set runtimepath=~/.vim,/var/lib/vim/addons,/usr/share/vim/vimfiles,/usr/share/vim/vim80,/usr/share/vim/vimfiles/after,/var/lib/vim/addons/after,~/.vim/after
mr-cal commented 4 years ago

I had this same error and learned that $VIMRUNTIME/syntax/cpp.vim was missing along with most other syntax files. I solved this problem by installing vim-data.