开发者的实用 Vim 插件:cppSyntaxCheck&syntastic

开发者的实用 Vim 插件:cppSyntaxCheck&syntastic_第1张图片

下载一个cppSyntaxChek配置如下:针对C++的,和SyntaxCheck混合使用,检测头文件就不会出现了,保存才刷新,开始进入文件会提示错误,没关系,因为没有刷新。

" For cppSyntaxCheck
let g:include_path=":. 
            \:/home/howard/qt/qt-embedded-4.8.5/include/QtCore 
            \:/home/howard/qt/qt-embedded-4.8.5/include/QtGui
            \:/usr/lib/llvm-3.8/include/llvm
            \:/usr/include/c++/5 
            \:/usr/lib/llvm-3.8/lib/clang/3.8.0/include"
let g:compile_flag="-D_LINUX_" 
let g:cpp_compiler="/usr/bin/g++" 
let g:enable_warning=1 
let g:cpp_compiler="LANG=C g++ -Wall" 
let g:longest_text=120

" For syntastic settings 这个是我的syntastic的配置
let g:syntastic_enable_highlighting = 1 " 错误单词高亮
let g:syntastic_aggregate_errors = 1 "第一时间检查发现任何错误
let g:syntastic_enable_signs = 1 
let g:syntastic_auto_loc_list = 1 
let g:syntastic_check_on_open = 1 
let g:syntastic_check_on_wq = 0 
let g:syntastic_always_populate_loc_list = 1 
let g:syntastic_stl_format = "[%E{Err: %fe #%e}%B{, }%W{Warn: %fw #%w}]"
let g:syntastic_debug_file = "~/syntastic.log"
" let g:syntastic_cpp_check_header = 1
let g:syntastic_cpp_checkers = ['gcc']

let g:syntastic_auto_jump = 1
let g:syntastic_enable_balloons = 1

let g:syntastic_cpp_compiler = 'g++'
let g:syntastic_cpp_compiler_options = '-std=c++11 -Wall -Wextra'

let g:syntastic_cpp_check_header = 1
let g:syntastic_cpp_auto_refresh_includes = 1

let g:syntastic_c_config_file = ['/home/howard/qt/qt-embedded-4.8.5/include/QtGui']
let g:syntastic_cpp_include_dirs = [
            \ '/home/howard/qt/qt-embedded-4.8.5/include/QtCore',
            \ '/home/howard/qt/qt-embedded-4.8.5/include/QtGui',
            \ '/usr/lib/llvm-3.8/include/llvm',
            \ '/usr/include/c++/5',
            \ '/usr/lib/llvm-3.8/lib/clang/3.8.0/include' ]

let g:syntastic_ignore_files=[".*\.py$", ".*\.S$"] "让 syntastic忽略 python 文件,和汇编文件
let g:syntastic_html_tidy_ignore_errors=[" proprietary attribute \"ng-"]
set statusline+=%#warningmsg#
set statusline+=%{SyntasticStatuslineFlag()}
set statusline+=%*

" YouCompleteMe options 这个自动补全的也有语法检测,需要关闭它的,配置如下
let g:ycm_enable_diagnostic_signs = 1 "诊断症状使能
let g:ycm_enable_diagnostic_highlighting = 0 "诊断语法彩笔做标记
let g:ycm_register_as_syntastic_checker = 1 " 使用syntastic检测语法
let g:ycm_error_symbol = '乄'
let g:ycm_warning_symbol = '〇'

" 修改高亮的背景色, 适应主题
highlight SyntasticErrorSign guifg=white guibg=black
function! ToggleErrors()
    let old_last_winnr = winnr('$')
    lclose
    if old_last_winnr == winnr('$')
        " Nothing was closed, open syntastic error location panel
        Errors
    endif
endfunction
nnoremap s :call ToggleErrors()
" nnoremap sn :lnext
" nnoremap sp :lprevious


" 以上配置比较常规了,乄表示错误提示,而且这里配置了syntastic的检测,YCM是对python语法检测,对C++很多bug。

 

 

最后补充一下:

Vim YCM+Syntastic插件找不到头文件问题

在.vimrc中设置g:syntastic_cpp_include_dirs,无效。

解决:

以kaldi工程为例,在.ycm_extra_conf.py文件的flags最后加入

'-isystem',

'/path/to/kaldi/src'

转载于:https://my.oschina.net/chaenomeles/blog/831252

你可能感兴趣的:(开发者的实用 Vim 插件:cppSyntaxCheck&syntastic)