搞了半天,应该是楼主记错了。这个和ycm的设置没关系,我今天先安装了ycm,我也一直怀疑是ycm的问题。其实问题是vim自己的filetype问题。
在/usr/share/vim/vim74/filetype.vim中
377 " .h files can be C, Ch C++, ObjC or ObjC++.
378 " Set c_syntax_for_h if you want C, ch_syntax_for_h if you want Ch. ObjC is
379 " detected automatically.
380 au BufNewFile,BufRead *.h call s:FTheader()
381
382 func! s:FTheader()
383 if match(getline(1, min([line("$"), 200])), '^@\(interface\|end\|class\)') > -1
384 if exists("g:c_syntax_for_h")
385 setf objc
386 else
387 setf objcpp
388 endif
389 elseif exists("g:c_syntax_for_h")
390 setf c
391 elseif exists("g:ch_syntax_for_h")
392 setf ch
393 else
394 setf cpp
395 endif
396 endfunc
这一段就是默认认为*.h为cpp,如果要设置为默认是c,设置g:c_syntax_for_h才行。
.vimrc添加let g:c_syntax_for_h=1
